Structure Storage in Memory

G

Guest

I know that Structures are Value types but I am not clear where a structre
data is stored, i.e., on stack or in managed heap when the strucutre contains
a reference type. For example;

Public Sturcture myStruct
public i as integer
public m() as Byte
End Structure

Since m is a reference type (array), where will the actual values of the
array be stored, i.e., on the stack or in the managed heap with only a
pointer on the stack?
 
A

Armin Zingler

Dennis said:
I know that Structures are Value types but I am not clear where a
structre data is stored, i.e., on stack or in managed heap when the
strucutre contains a reference type. For example;

Public Sturcture myStruct
public i as integer
public m() as Byte
End Structure

Since m is a reference type (array), where will the actual values of
the array be stored, i.e., on the stack or in the managed heap with
only a pointer on the stack?

The latter one is true:

dim var as myStruct

If var is a local variable, var is stored on the stack. This includes the
Integer value and a reference to the byte array. Consequently variable var
occupies 8 bytes on the stack. Every instance of myStruct occupies 8 bytes.
(at least on a 32-bit system with no padding bytes). The array data itself
is stored in managed heap.



Armin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top