LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Allocate memory for buffers

Hello,

 

I'm trying to allocate memory through using a buffer via LabVIEW.  I understand I'm supposed to use an array, yet I'm not sure how I'm supposed to do this. Would you be able to provide an example, or provide an explanation how this is accomplished? I'd think it should be relatively easy to find how to do this, but I don't seem to be hitting the right sources. 

 

Thanks, 

Andrea 

0 Kudos
Message 1 of 5
(3,249 Views)
A buffer to do what? Would this be related to your earlier thread? The Initialize Array function can be used to create an instance of an array at run-time.
0 Kudos
Message 2 of 5
(3,241 Views)

Hi,

 

 

The method to initialise the array is quite right, but be specific on what you want, probably your vi would help.

if you attach it here.

 

 

Regards,

 

shrek

0 Kudos
Message 3 of 5
(3,235 Views)

In order to allocate memory into the buffers, here is the C code I am trying to accomplish:

 

/* Allocate memory for buffer */

pBuffer1 = (UCHAR *)AllocateMemU32(byteSize / 4 + 2) 

 

In order to fill it, this is the C code involved: 

 

/* Construct the start of the packet */

pBuffer1[0] = transmitLink;
pBuffer1[1] = g_usbport;
pBuffer1[2] = MENU_LOOPBACK;

 

/* Fill send buffer with random data, receive buffer with zeros */

FillBuffer((U32 *)(pBuffer1 + 3), byteSize / 4 + 1, DATA_TYPE_COUNT);

 

Thanks, 

Andrea 

0 Kudos
Message 4 of 5
(3,200 Views)

You do not need to allocate memory at all, LV is doing this for you automagically.

 

There are several ways to get an array:

* Use the build array function (you can resize it, it allows inputs of single as well as array), this is fully dynamically and also works as AppendToArray.

* Use the Initalize array to get an array of defined size with all values initalized the same; Usful if you have large amount of data and are concerned about performance (then you use the replace array element function to set the values one by one or subset by subset)

* Use the autoindexing of a loop output (for- or while-, for gives optimal performance)

 

Please do not think the same way as when programming C or similar. Graphical programming has no variables but wires. Because each wire is mapped to a memory location, the wire itself has already the information for the compiler and you do not need (and hence they are not available as functions) use any of the MemAlloc, MemFree or similar...

 

Felix

0 Kudos
Message 5 of 5
(3,189 Views)