LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Create Network Stream endpoint - pre-allocation for strings

Solved!
Go to solution

Hi,

 

I would like to use ellement allocation mode input to pre-allocate memory on my RT target. My concern is how to allocate memory for specific string size.

 

Due to documentation

"pre-allocate specifies that buffer memory allocation occurs when the endpoint is created. The element wired to the data type input determines the amount of memory allocated for each element. If a larger element is added to the buffer during run-time, additional memory is allocated dynamically. "

 

I understand that if I wire string constant to the data type, 40 to the buffer size I will receive buffer for 40 strings. But how long strings ? One character ?

I don't want let memory manager to run after endpoint creation so I would like to allocate enought big memory space (for example 40 string, 10 characters each).

 

Is it possible to do it connecting string constant (e.g. with 10 characters) or I have to put my specific size string to the cluster ?

Another maybe trival question, is it possible to check how big buffer was allocated by this VI ?

 

Kamil

0 Kudos
Message 1 of 5
(2,511 Views)

I'm prepared to be proven wrong on this, but I suspect that when you "allocate" a String, and probably when you allocate an Array, you are really saying how many pointers to memory (where the Strings and Arrays will be ultimately saved) do you need.  You can allocate Arrays (say, an array of 1000 Dbl) which will allocate sufficient memory to hold this array, but there's nothing to keep you from adding more points -- it only "costs" you when more memory needs to be allocated.  

 

Note -- I just confirmed that the above seems to be true for Queues, but for RT FIFOs, if the elements are Arrays, you specify not only how many elements, but the Array size.  I don't see this control for Strings, but then FIFOs don't support Variable-sized elements such as Strings ...

 

Bob Schor

Message 2 of 5
(2,487 Views)
Solution
Accepted by topic author KamilK

Hello,

 

Here is some further information on memory allocation for network streams:

 

http://www.ni.com/white-paper/12267/en/

 

My guess is that in order to preallocate buffers for non scalar datatypes, you will have to write "dummy" elements of the desired size to the stream, read or flush out those "dummy" elements bevore using the stream in normaly.

 

Best Regards!

 

Message 3 of 5
(2,455 Views)

Thanks Bob, Wetzer,

 

I was thinking about network stream not RT FIFO but your answer helped me to understand topic 🙂 In the link from Wetzer I found confirmation. During endpoint creation it will be allocated only place for the pointers. It is not possible to allocate place for non-scalar data types imediatelly.

 

"On the other hand, the amount of memory consumed when dealing with non-scalar data types such as clusters, strings, and arrays isn’t as straightforward.  The size of these data types can vary at runtime, so the total amount of memory required isn’t known when the endpoint is created.  In these cases, the buffer allocated when creating the endpoint is only large enough for each element to hold a pointer or handle to a data value written to that element in the buffer.  The memory required to store each element’s data value is then allocated dynamically at runtime as elements are written to the buffer. On the other hand, the amount of memory consumed when dealing with non-scalar data types such as clusters, strings, and arrays isn’t as straightforward. The size of these data types can vary at runtime, so the total amount of memory required isn’t known when the endpoint is created. In these cases, the buffer allocated when creating the endpoint is only large enough for each element to hold a pointer or handle to a data value written to that element in the buffer. The memory required to store each element’s data value is then allocated dynamically at runtime as elements are written to the buffer"

0 Kudos
Message 4 of 5
(2,448 Views)

The size of the string wired to the data type terminal is the size of the string that will be allocated initially to each element in the buffer.  So in your example, if you wire a string constant of 10 characters and specify a buffer size of 40 elements, you'll end up allocating space for 40 strings that are 10 characters each.  If you then write a string longer than this at runtime, that element slot in the buffer will grow to accomodate the larger string and retain that new size until a larger element is written or the endpoint is destroyed.

0 Kudos
Message 5 of 5
(2,248 Views)