473,624 Members | 2,453 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 1022
"Dennis" <De****@discuss ions.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****@discuss ions.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
6642
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
2157
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 space remains, a bit-field that immediately follows another bit-field in a structure shall be packed into adjacent bits of the same unit. If insufficient space remains, whether a bit-field that does not fit is put into the next unit or overlaps...
6
2617
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. My basic need is:
8
3440
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 I access the array elements. Thanks for your help. #include <stdio.h>
20
8796
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 understanding the use of it? Can somebody explain this?
0
8240
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8175
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8336
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6111
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5565
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4082
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2610
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 we have to send another system
1
1791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1487
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.