LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Custom 64-bit refnum

I have a question about creating a custom refnum on a 64-bit OS.  I'm using LV 2012SP1 on Win7, both 64-bit.

I have a DLL with an "open" function that allocates some memory and returns a pointer to that memory, several functions that manipulate data stored in the allocated memory, and finally a "close" function that cleans up and deallocates the memory.  All of these functions need to be called from LabVIEW, so the pointer needs to be passed around. Since I'm on a 64-bit OS pointers are 8 bytes. 

 

One solution is to cast the pointer to an unsigned 64-bit integer, and pass it around LabVIEW on a blue wire.  That's fine, and it works.  It would be better, however, to cast the pointer to a refnum and pass it around on a turquoise wire so it's clear to users that this thing is not an integer but actually a reference. 

 

After some searching through the forums, it seems like the accepted way to do this on 32-bit systems is to cast the pointer to a datalog refnum containing a single-element enum typedef.  However, this doesn't seem to work with 64-bit pointers.  I'm not sure if this is because the enum is limited to only 32 bits (why is that, anyway?) or some other reason.  I mean, if refnums really are pointers under the hood, don't they have to be 64 bits on a 64-bit OS? Does anyone know if there is a way to cast a 64-bit integer to a refnum in LabVIEW?

Download All
0 Kudos
Message 1 of 7
(2,921 Views)

Do you want an overkill solution?  Make a class and have the only thing in the private data type of the class a U64.  This will mean that functions without the correct privlages can't touch the data in it.  This will prevent users from messing with your data.  But then the functions in the class can have access to the data.  You can even control the shape and color of your class wire so you can have it resemble the turqoise refnum.

 

No idea why the example you shown doesn't work but it is probably as you suspect, that the refnum is a U32 under the hood.

0 Kudos
Message 2 of 7
(2,882 Views)

Thanks for the reply, Hooovah.  No, I don't really want an overkill solution, but thanks for the thought.  For now I'm just passing the pointer around as an integer since it's easy and it works.  It just seems odd to me that refnums are 32 bits on a 64 bit platform.

 

0 Kudos
Message 3 of 7
(2,877 Views)

I think that in most C/C++ compilers, enums are limited to 32 bits. Perhaps this is the root cause.

0 Kudos
Message 4 of 7
(2,855 Views)

Are you sure your LV installation is 64-bit?

 

Irrespective of the bitness of your OS if LabVIEW is installed as 32-bit (default BTW) then your pointers within LV are going to be 32-bit.

0 Kudos
Message 5 of 7
(2,844 Views)

Yes, I'm sure that my LV installation is 64-bit.

0 Kudos
Message 6 of 7
(2,820 Views)

Jimsonweed - It seems reasonable that the 32 bit limit on LV enums stems from a compiler.  But then it seems that enums would no longer work to store pointers on a 64-bit platform.  I don't see how to get around the fact that if a refnum is storing a pointer on a 64 bit platform, then the underlying data type must be at least 64 bits. 

0 Kudos
Message 7 of 7
(2,814 Views)