Admin Production ni-theme
Current Publication

Allocating Memory for Network Stream Endpoint Buffers

LabWindows/CVI

Allocating Memory for Network Stream Endpoint Buffers

Network stream endpoints use a FIFO buffer to transfer data. The dataType, numItems (or numArrays) and itemSize (or arraySize) parameters of the CNSNew...Endpoint functions determine how much memory the buffer requires. You can specify how initial buffer memory is allocated for non-scalar data types with the itemSize and arraySize parameters.

Regardless of the allocation mode you select, buffer size affects the amount of memory your application uses. Always monitor memory usage when testing your applications.

Specifying the Allocation Mode for Network Stream Endpoint Buffers

You can either pre-allocate memory or allocate memory as needed for network stream endpoint buffers.

Allocate memory as needed if your application transfers non-scalar data and you cannot determine the maximum size of each data element before run time. When you allocate as needed, LabWindows/CVI allocates only enough memory to create a pointer or handle for each data element when the network stream is created. LabWindows/CVI then dynamically allocates additional memory for each element as it enters the buffer. To allocate memory as needed, specify 0 for the itemSize and arraySize parameters.

Pre-allocate memory if your application transfers non-scalar data and you can determine the maximum size of each data element at edit time. When you pre-allocate, the CNSNew...Endpoint functions allocate initial buffer memory based on the numItems or numArrays parameters and itemSize or arraySize parameters.

You must pre-allocate memory for scalar data transfers (excluding strings). For scalar data transfers, the Network Streams Library allocates numItems * the size of the data type and ignores the itemSize parameter.

To pre-allocate an endpoint buffer, you must specify a value that is the maximum expected size to the dataType parameter.

Note  Additional memory is allocated dynamically if an element requires more than the pre-allocated amount of memory at run time.