LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Memory Allocation for Cluster?

When I create a cluster (e.g. by wire branch) the compiler must allocate new memory.
Is the memory for the new cluster allocated from the stack or the heap?


In LabVIEW we often talk about buffer allocations and efficient programming techniques. But is seems that there is still some information missing. There is a difference between  memory allocated from the heap and memory allocated from the stack. When building  an array (or creating a copy by wire branch) the memory is allocated from the heap, so LabVIEW memory manager is called. This is well documented.

 

How is memory allocated for clusters, when I create a copy of a cluster (e.g. by wire branch) it could slow down the code a little and increase (overall memory usage) but even for RT code this is not necessarily important. It is more important to know whether the memory is allocated from the stack or the heap? If the memory is allocated from the heap, the LabVIEW memory manager will be called and code will not be deterministic. If on the other hand, memory comes from the Stack the code is still deterministic.

 

 

Please advise? (if certain of answer)

 

Thanks

Mark

0 Kudos
Message 1 of 13
(4,319 Views)

The idea of "stack" and "heap" have different meanings in LV.

 

All memory allocation operations are non-deterministic.

 

Start your research by studying what we did in this thread. Thi simage is a preview of what you will find there. "Gird up your loins", it is not easy reading.

 

 

 

 

If you have follow-up Q's post them there along with your benchmarking code.

 

The links in this tag cloud could also make for good reading.

 

Ben

Message Edited by Ben on 12-09-2009 08:46 AM
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 2 of 13
(4,280 Views)

Hi Mark,

 

I would suggest you to contact your local NI Office with this request.

 

 

Thanks,

Christian

0 Kudos
Message 3 of 13
(4,253 Views)

Ups, somhow I posted to the wrong thread, so please ignore my last post!

 

@Ben: Great answer, that's a quite nice thread you linked there. Btw, as far as i know Smiley Wink

0 Kudos
Message 4 of 13
(4,240 Views)

Thanks Ben it is an excellent thread, but it will take some time to read and understand properly.

 

I'm not sure that it explains every thing about the problem/question that I have.

If every buffer/branch requires memory from the LabVIEW memory manager, it seems nearly impossible to write deterministic code.

I'll post again with an example after I have read some more.

 

Message Edited by sparkymark567 on 12-09-2009 11:35 AM
0 Kudos
Message 5 of 13
(4,223 Views)
I don't know whats going on today but first I answer to the wrong thread and then I don't finish my sentences

Christian_M wrote:

 

 

@Ben: Great answer, that's a quite nice thread you linked there. Btw, as far as i know Smiley Wink


Btw, as far as i know it will be allocated in the heap Smiley Wink

0 Kudos
Message 6 of 13
(4,220 Views)

sparkymark567 wrote:

Thanks Ben it is an excellent thread, but it will take some time to read and understand properly.

 

I'm not sure that it explains every thing about the problem/question that I have.

If every buffer/branch requires memory from the LabVIEW memory manager, it seems nearly impossible to write deterministic code.

I'll post again with an example after I have read some more.

 

Message Edited by sparkymark567 on 12-09-2009 11:35 AM

It is possible to write deterministic code in LV (closed a loop at almost 200KHz deterministically).

 

But to do so you have to understand what force a a memory allocation and WHEN is needs to be allocated. Take a look at this tag cloud for LABVIEW performance. THey word you want to learn and master is "in-placeness".

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 7 of 13
(4,215 Views)

I do absolutely need to understand how memory is allocated.
I am however less bothered about performance , I just want a highly reliable thread that does not block.
One situation where blocking could occur is when the LabVIEW memory manager is called.
I would really like to see when the memory manager is called during debug, but there does not seem to be an easy way to do it.
Maybe there is some hack available?

As far as I can guess:
The memory manager is only called when dynamic memory allocation is required, but I do not think that buffers are created in this way.

Each time there is a buffer, the execution speed will suffer because LabVIEW must copy the data in/out of the buffer.
It is useful to know where the buffers exist, but I not think it affects determinism directly.

The confusion arises, because an Array is a reference type.
When there is a wire branch (or buffer) using an Array, LabVIEW must use dynamic memory allocation to create the buffer space (or wire branch copy).

But, I'm not sure that this also applies to a cluster? A cluster (seems similar to a C struct) and is probably a value type?

For now then, I just need to know whether a Cluster is a value type or a reference type?

 

0 Kudos
Message 8 of 13
(4,177 Views)

sparkymark567 wrote:

I do absolutely need to understand how memory is allocated.
I am however less bothered about performance , I just want a highly reliable thread that does not block.
One situation where blocking could occur is when the LabVIEW memory manager is called.
I would really like to see when the memory manager is called during debug, but there does not seem to be an easy way to do it.
Maybe there is some hack available?

As far as I can guess:
The memory manager is only called when dynamic memory allocation is required, but I do not think that buffers are created in this way.

Each time there is a buffer, the execution speed will suffer because LabVIEW must copy the data in/out of the buffer.
It is useful to know where the buffers exist, but I not think it affects determinism directly.

The confusion arises, because an Array is a reference type.
When there is a wire branch (or buffer) using an Array, LabVIEW must use dynamic memory allocation to create the buffer space (or wire branch copy).

But, I'm not sure that this also applies to a cluster? A cluster (seems similar to a C struct) and is probably a value type?

For now then, I just need to know whether a Cluster is a value type or a reference type?

 


 

I posted links to threads that covers all of your questions. It appears that you did not investigate any of them. Smiley Sad

 

If you had investigated those links you would have learned how to benchmark your VIs (this is the ultimate bottom line to determine where when and how buffers are created and copied) as well as

 

Tools >>> Profile >>> Show Buffer Allocations

 

I am more than happy to help people learn about all aspects of LV that affect the performance (speed, determinism or whatever) but I can not read the links for you.

 

Hoping you will read what has already been posted,

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 9 of 13
(4,163 Views)

Hi Ben, I forgot to mention the links do not work.

Otherwise I would read all of them.

0 Kudos
Message 10 of 13
(4,160 Views)