473,326 Members | 2,182 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,326 software developers and data experts.

Memory allocation in managed code

2
Here's a seemingly simple issue that has me scratching my head. In the following snippet of managed code (C#), I declare some integers without assigning them values.

Expand|Select|Wrap|Line Numbers
  1. static void Main()
  2. {
  3.   int x;
  4.   int y;
  5.   int z;
  6. }
Next I put a breakpoint on z or the closing brace and I view the address of each variable in my watch window. So, &x, &y, &z. And it looks normal. Each varialbe has an address and has been initialized to a value of 0.

Expand|Select|Wrap|Line Numbers
  1. -&x    0x03abecc4
  2.     x    0
  3. -&y    0x03abecc0
  4.     y    0
  5. -&z    0x03abecbc
  6.     z    0
Now, if I assign a values to x and y,

Expand|Select|Wrap|Line Numbers
  1. static void Main()
  2. {
  3.   int x = 0;
  4.   int y = 1;
  5.   int z;
  6. }
my watch window now shows

Expand|Select|Wrap|Line Numbers
  1. &x    Expression has no address
  2. &y    Expression has no address
  3. -&z    0x03abecbc
  4.     z    0    int
That is, x and y now supposedly have no address, but do have a value. How is that possible?

And this seems to be the case with any CLR language, not just C#.

However, if I try the same thing in unmanaged C, I get what I expect.

Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3.   int x = 1;
  4.   int y = 1;
  5.   int z = 1;
  6.   return 0;
  7. }
Expand|Select|Wrap|Line Numbers
  1. -&x    0x0012ff60
  2.  
  3. -&y    0x0012ff54
  4.     1
  5. -&z    0x0012ff48
  6.     -858993460
I'm using VS2005. Any ideas?
Apr 20 '07 #1
1 1109
mikeA
2
Sorry, for those last two code blocks, I meant to post:

Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3.   int x = 0;
  4.   int y = 1;
  5.   int z;
  6.   return 0;
  7. }
Expand|Select|Wrap|Line Numbers
  1. -&x    0x0012ff60
  2.  
  3. -&y    0x0012ff54
  4.     1
  5. -&z    0x0012ff48
  6.     -858993460
Apr 20 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Andreas Suurkuusk | last post by:
Hi, I just noticed your post in the "C# memory problem: no end for our problem?" thread. In the post you implied that I do not how the garbage collector works and that I mislead people. Since...
6
by: Tom | last post by:
We have a VERY simple .NET C# Form Application, that has about a 23MB Memory Footprint. It starts a window runs a process and does a regular expression. I have done a GC.Collect to make sure that,...
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...
9
by: Mike P | last post by:
I know everything about reference counting and making sure you don't have large objects lying around. I have also profiled my app with multiple tools. I know about the fact GC collects memory but...
15
by: Chetan Raj | last post by:
Hi All, We have a web-application in asp.net that interacts with legacy code written in COM. The memory usage in aspnet_wp.exe increases every sec and never reduces. Using the .NET performance...
30
by: MAG1301 | last post by:
I've detected memory leaks in our huge .NET 1.1 C# application but couldn't localize them directly. So I've reduced the code to the following console application: using System; using System.IO;...
9
by: Adam Right | last post by:
Hi, Anyone suffers from the high memory usage of C# in windows applications? Is there a solution for that problem? Thanks...
81
by: Peter Olcott | last post by:
It looks like System::Collections::Generic.List throws and OUT_OF_MEMORY exception whenever memory allocated exceeds 256 MB. I have 1024 MB on my system so I am not even out of physical RAM, much...
34
by: jacob navia | last post by:
Suppose that you have a module that always allocates memory without ever releasing it because the guy that wrote it was lazy, as lazy as me. Now, you want to reuse it in a loop. What do you do?...
3
by: not_a_commie | last post by:
The CLR won't garbage collect until it needs to. You should see the memory usage climb for some time before stabilizing. Can you change your declaration to use the 'out' keyword rather than a 'ref'...
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...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
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...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.