Same pointer to two different type variables of same length?
Same pointer to two different type variables of same length?
Same pointer to two different type variables of same length?
Same pointer to two different type variables of same length?
Same pointer to two different type variables of same length?
Same pointer to two different type variables of same length? Same pointer to two different type variables of same length? Same pointer to two different type variables of same length? Same pointer to two different type variables of same length? Same pointer to two different type variables of same length? Same pointer to two different type variables of same length? Same pointer to two different type variables of same length? Same pointer to two different type variables of same length?
Same pointer to two different type variables of same length? Same pointer to two different type variables of same length?
Same pointer to two different type variables of same length?
Go Back  Xtreme Visual Basic Talk > > > Same pointer to two different type variables of same length?


Reply
 
Thread Tools Display Modes
  #1  
Old 10-19-2016, 11:12 PM
Cerian Knight's Avatar
Cerian KnightSame pointer to two different type variables of same length? Cerian Knight is offline
Polymath (in disciplina)

Super Moderator
* Expert *
 
Join Date: May 2004
Location: Michigan
Posts: 4,159
Default Same pointer to two different type variables of same length?


I have two simple UDTs, D1 containing a Double and D2 containing two Longs. In order to inspect the bits of the D1 value (which must be a Double), I find it expedient to LSET D2 = D1. All is well (with this specific example, anyway).

However, I noticed that LSET imposes a noticeable performance penalty (nearly 20% in my test code) that I could resolve (if I knew how) by forcing the memory pointer of D2 to point to D1 (or a non-UDT Double) until cleanup is required, similar to what is done with dual referencing SAFEARRAYs using VarPtrArray.

Actually, I suppose that I could accomplish this with 1 and 2 element arrays using VarPtrArray, but would rather not unless there is no other choice.

Any advice or options are welcome.
__________________
I got all the answers wrong on the GLAT, apparently even #9 (where I put a period in the middle of the box and labeled it 'singularity ripe for rapid inflation').

Last edited by Cerian Knight; 10-20-2016 at 07:51 AM.
Reply With Quote
  #2  
Old 10-22-2016, 09:17 PM
OnErr0r's Avatar
OnErr0rSame pointer to two different type variables of same length? OnErr0r is offline
Obsessive OPtimizer

Administrator
* Guru *
 
Join Date: Jun 2002
Location: Debug Window
Posts: 13,767
Default

One alternative would be to use PutMem8, which is an msvbvm call. You can make the call even faster by creating a TLB and turning off error checking.

http://www.xtremevbtalk.com/762464-post4.html
__________________
Quis custodiet ipsos custodues.
Reply With Quote
  #3  
Old 10-23-2016, 06:26 PM
Cerian Knight's Avatar
Cerian KnightSame pointer to two different type variables of same length? Cerian Knight is offline
Polymath (in disciplina)

Super Moderator
* Expert *
 
Join Date: May 2004
Location: Michigan
Posts: 4,159
Default

I partially side-stepped the issue by using an array of pre-calculated longs, but I am not entirely happy with all aspects of the result.

I may create an alternative function using PutMem8 if it works out as an LSET replacement.

Thanks!
__________________
I got all the answers wrong on the GLAT, apparently even #9 (where I put a period in the middle of the box and labeled it 'singularity ripe for rapid inflation').
Reply With Quote
  #4  
Old 10-23-2016, 06:56 PM
OnErr0r's Avatar
OnErr0rSame pointer to two different type variables of same length? OnErr0r is offline
Obsessive OPtimizer

Administrator
* Guru *
 
Join Date: Jun 2002
Location: Debug Window
Posts: 13,767
Default

Sorry, that should be GetMem8. Hope it works out.
__________________
Quis custodiet ipsos custodues.
Reply With Quote
  #5  
Old 10-24-2016, 11:06 AM
Cerian Knight's Avatar
Cerian KnightSame pointer to two different type variables of same length? Cerian Knight is offline
Polymath (in disciplina)

Super Moderator
* Expert *
 
Join Date: May 2004
Location: Michigan
Posts: 4,159
Default

GetMem8 and PutMem8 both work (after adjusting the Declares for each). Perhaps GetMem8 is a little faster than PutMem8 (at least with with my current code alignment, but no TLB).

The good news is... about a 6% performance improvement overall (which is more in line with my expectations)! Part of that improvement might also be related to now changing the UDT Double to a standard Double...

If that is the case... is there any guaranteed way to memory align two the destination Longs without UDT encapsulation? Inspecting the VarPtrs suggests that the answer is no.

Thanks again.
__________________
I got all the answers wrong on the GLAT, apparently even #9 (where I put a period in the middle of the box and labeled it 'singularity ripe for rapid inflation').
Reply With Quote
  #6  
Old 10-24-2016, 11:06 PM
OnErr0r's Avatar
OnErr0rSame pointer to two different type variables of same length? OnErr0r is offline
Obsessive OPtimizer

Administrator
* Guru *
 
Join Date: Jun 2002
Location: Debug Window
Posts: 13,767
Default

Currency are 64 bits, but I doubt that will be helpful. Shame vb6 didn't have a longlong.
__________________
Quis custodiet ipsos custodues.
Reply With Quote
  #7  
Old 10-25-2016, 01:10 AM
dilettante's Avatar
dilettanteSame pointer to two different type variables of same length? dilettante is offline
Underclocked lifestyle

Forum Leader
* Guru *
 
Join Date: Feb 2005
Location: Michigan, USA
Posts: 4,514
Default

That's what happens when a tool is left abandoned after 1998.

If you are playing with a ton of these so that performance really matters you could always move loops into another language that can compile a DLL.
Reply With Quote
  #8  
Old 10-27-2016, 09:13 AM
Cerian Knight's Avatar
Cerian KnightSame pointer to two different type variables of same length? Cerian Knight is offline
Polymath (in disciplina)

Super Moderator
* Expert *
 
Join Date: May 2004
Location: Michigan
Posts: 4,159
Default

The phrase 'move loops' caught my attention (thanks!) in an unusual way as I pondered common CPU pipe-line architectures (and their limits). So I un-rolled an internal short-cycle (17 step) iterator with conditional checks (creating an unsightly amount of repetitive code in the process). With iterator and conditional checks gone I got a 50% performance boost.

Just for grins, I took the new code and reverted from GetMem8 back to LSET/UDT-Double, instantly losing over 16% of my new-found gains!

So, indeed, GetMem8 rocks. Hopefully the VB.NET ports of some of my more esoteric code will be less problematic due to the more flexible/intrinsic data types supported.
__________________
I got all the answers wrong on the GLAT, apparently even #9 (where I put a period in the middle of the box and labeled it 'singularity ripe for rapid inflation').
Reply With Quote
  #9  
Old 10-29-2016, 11:04 PM
Cerian Knight's Avatar
Cerian KnightSame pointer to two different type variables of same length? Cerian Knight is offline
Polymath (in disciplina)

Super Moderator
* Expert *
 
Join Date: May 2004
Location: Michigan
Posts: 4,159
Default

Moving along, I downloaded VBVM6Lib.tlb from here: Dope'n'Declarations
Eventually, I guessed that GetMem8 is called AssignQWord, which the following was only marginally helpful with: VBVM6: A Visual Basic TypeLib for memory access
Got 5-9% additional performance over GetMem8 (and works fine in IDE). The tlb also has a DLong variable type built in, but it works/performs the same as the UDT I made.

Thanks again!
__________________
I got all the answers wrong on the GLAT, apparently even #9 (where I put a period in the middle of the box and labeled it 'singularity ripe for rapid inflation').
Reply With Quote
Reply

Tags
double, varptrarray, lset, pointer, non-udt, safearrays, memory, referencing, dual, similar, cleanup, required, arrays, choice, advice, options, accomplish, element, forcing, suppose, noticeable, bits, inspect, longs, variables


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Same pointer to two different type variables of same length?
Same pointer to two different type variables of same length?
Same pointer to two different type variables of same length? Same pointer to two different type variables of same length?
Same pointer to two different type variables of same length?
Same pointer to two different type variables of same length?
Same pointer to two different type variables of same length? Same pointer to two different type variables of same length? Same pointer to two different type variables of same length? Same pointer to two different type variables of same length? Same pointer to two different type variables of same length? Same pointer to two different type variables of same length? Same pointer to two different type variables of same length?
Same pointer to two different type variables of same length?
Same pointer to two different type variables of same length?
 
Same pointer to two different type variables of same length?
Same pointer to two different type variables of same length?
 
-->