473,327 Members | 1,919 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Memory allocation for value types...

We know that value types are stored at stack are and reference types are
stored at heap area...

If class is look like this..

class Sample
{
int count;
double sal;
}

class MainEntry
{
static void Main()
{
Sample Obj=new Sample();
}
}
Here where the value types are stored in Sample class?

Thanks,
Veera.
Jul 24 '06 #1
2 2733
Hello veera,

Citing Jon
"Instance variables for a value type are stored in the same context as the
variable that declares the value type. The memory slot for the instance effectively
contains the slots for each field within the instance. That means that a
struct variable declared within a method will always be on the stack, whereas
a struct variable which is an instance field of a class will be on the heap.
"

Read this http://www.yoda.arachsys.com/csharp/memory.html
vkWe know that value types are stored at stack are and reference types
vkare stored at heap area...
vk>
vkIf class is look like this..
vk>
vkclass Sample
vk{
vkint count;
vkdouble sal;
vk}
vkclass MainEntry
vk{
vkstatic void Main()
vk{
vkSample Obj=new Sample();
vk}
vk}
vkHere where the value types are stored in Sample class?
vk>
vkThanks,
vkVeera.
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Jul 24 '06 #2
veera sekhar kota <ve*************@discussions.microsoft.comwrote:
We know that value types are stored at stack are and reference types are
stored at heap area...
Well, you may think you know that, but it's not the truth - or at least
not the whole truth.
If class is look like this..

class Sample
{
int count;
double sal;
}

class MainEntry
{
static void Main()
{
Sample Obj=new Sample();
}
}
Here where the value types are stored in Sample class?
On the heap, as part of the data for the object. It's unfortunate that
so many people blithely state that value types are stored on the stack.
See http://www.pobox.com/~skeet/csharp/memory.html for more information
on this.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jul 24 '06 #3

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

Similar topics

18
by: Tron Thomas | last post by:
Given the following information about memory management in C++: ----- The c-runtime dynamic memory manager (and most other commercial memory managers) has issues with fragmentation similar to a...
7
by: Office Drone | last post by:
I'm a bit confused about memory usage, and for some reason I wasn't able to find a single point-of-call to get the amount of memory available. If we take, for instance, the Windows platform: ...
8
by: Berk Birand | last post by:
Hi all, I have to use C-style structures for an assignement. I cannot have any methods or constructors for it. What has surprised me is that in my code, I have to allocate memory for an array of...
4
by: kk | last post by:
Hi all, i didn't get output in the following code while compiling and executing with g++ version 3.2.3 it doesn't allocate memory to pointer varaible (x) in class B. and it gives correct output...
5
by: Uday Joshi | last post by:
Hi look at the code below /* test.c */ int main(int argc, char *argv) { int *x; *x = 10; printf("%d\n", *x); return 0;
9
by: CptDondo | last post by:
I am working on an embedded platform which has a block of battery-backed RAM. I need to store various types of data in this block of memory - for example, bitmapped data for control registers,...
6
by: Michael Isaacs | last post by:
Regarding use of enum's, I am wondering what the cost of memory is when creating the enumeration on the calling side, and then using it on the function/method side. See example below. If I...
62
by: ivan.leben | last post by:
How can I really delete a preloaded image from memory/disk cache? Let's say I preload an image by creating an Image object and setting its src attribute to desired URL: var img = new Image();...
3
by: dizzy | last post by:
Hi I wonder if this code is standard conformant and should work on all conformant implementations (for some type T): 1: void* mem = ::operator new(sizeof(T)); 2: T* p = new(mem) T(args...);...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.