473,499 Members | 1,533 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Structure Storage in Memory

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?
--
Dennis in Houston
Mar 15 '06 #1
2 1014
"Dennis" <De****@discussions.microsoft.com> schrieb
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

Mar 15 '06 #2
Thanks much...you've given me confidence to use large arrays in strucutures.
--
Dennis in Houston
"Armin Zingler" wrote:
"Dennis" <De****@discussions.microsoft.com> schrieb
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

Mar 15 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
6616
by: simon | last post by:
From my previous post... If I have a structure, struct sFileData { char*sSomeString1; char*sSomeString2; int iSomeNum1; int iSomeNum2;
1
2147
by: Jeff | last post by:
Dear all, I was reading the ISO/IEC 9899 , and see the following thing: 6.7.1 10 . An implementation may allocate any addressable storage unit large enough to hold a bit- field. If enough...
6
2605
by: James | last post by:
I am using vb.net and need to keep in memory a large data structure, so I am looking for the best option. And after several test I am pretty confused. So I will be grateful if anyone can help me. ...
8
3432
by: SP | last post by:
The following code crashes after I add the two nested FOR loops at the end, I am starting to learn about pointers and would like to understand what I'm doing wrong. I think the problem is the way...
20
8771
by: dspfun | last post by:
I've come a across a program that declares the following data structure. typedef struct node { struct node *next; } node; It looks like a recursive data structure but I'm having trouble...
0
7171
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7220
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6893
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5468
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4918
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3090
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
664
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
295
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.