473,698 Members | 2,134 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

displaying memory in the debugger ... lags?

2 New Member
This is curious and hoping someone can enlighten me. Inside a C# console app I do
Expand|Select|Wrap|Line Numbers
  1. decimal mydecimal;
  2. mydecimal=2.0m;
  3.  
and then break and look at the memory window. I diplay the address of mydecimal and it does not contain what I expect. But if I edit the value of mydecimal in the debugger, I do see the memory window show what I expect. Then I can even put in back to what it was originally and it is what I expect.

I'm trying to be articulate and struggling but here is an example. If I break right after that mydecimal assignment and I see the following in the memory window. (0x0450ecb0 is the address of mydecimal.
0x0450ECB0 00010000 00000000 00000014 ............

Then, I change mydecmal from 2 to 1 in the watch window and the memory changes to the following (which is what I expect)
0x0450ECB0 00000000 00000000 00000001

The in the watch window I change mydecimal back to 2 and see the following (again what I expect)
0x0450ECB0 00000000 00000000 00000002

What's gong on with that first display? Why don't I see what I think I should? Am I expecting the right thing? Does this have somethng to do with flushing?

Advice is much appreciated. Thanks.
-ted
Nov 4 '07 #1
1 1176
tkubaska
2 New Member
I'm answering my own question here (I think). In any case, what I wrote is consistent. I have the feeling I'm in a minority when I care about these things, but if you're into this too and you see I've said something wrong, please let me know.

Now the key point about all this stuff is that very shortly this decimal representation that C# uses will not be IEEE compliant (because the standard is changing). I don't think the difference will be easily apparent to users; the answers will be the same most (if not essentially all) of the time. But there are a lot of smart people out there and I wouldn't be surprised if someone can engineer a scenario that gives different answers.

Basically what you have currently is a 96-bit decimal number (not counting sign and exponent) in 128 bits. Here are some examples showing the full 128 bits with the MSB on the left and the LSB on the right.

00000000 204FCE5E 3E250261 0FFFFFFF for 999999999999999 9999999999999
80000000 204FCE5E 3E250261 0FFFFFFF for -999999999999999 9999999999999
001C0000 204FCE5E 3E250261 0FFFFFFF for .99999999999999 99999999999999

The decimal type takes up 128 bits, but all those 128 bits are not used. The decimal number really is a mantissa (I always like to call this the significand), an exponent (base 10), and a sign.

The significand takes up 96 bits, but that’s not to say that the maximum significand is 96 ones. It’s not. You’re limited to 28 decimal digits.

Add another digit and you get an overflow. That is, enter 999999999999999 99999999999991 gives an overflow. Add a decimal point (with digits after the decimal point that remain less that 0.5) and you get the same number.
00000000 204FCE5E 3E250261 0FFFFFFF
for 999999999999999 9999999999999.4 99999 and
for 999999999999999 9999999999999

If you add a decimal point (with digits that total >= 0.5), you get one more bit in the significand, but never any more.
00000000 204FCE5E 3E250261 10000000
for 999999999999999 9999999999999.5 and
for 999999999999999 9999999999999.9 99999

What about that sign and exponent? The biggest exponent you can get is 28. Here’s a number that produces it.
001C0000 204FCE5E 3E250261 0FFFFFFF for .99999999999999 99999999999999

That means that the exponent doesn’t take up more than 5 bits, but the max exponent is not 5 ones. It’s 1C.
The MSB is the sign bit. Here's a negative number.

801C0000 204FCE5E 3E250261 0FFFFFFF for -.99999999999999 99999999999999

I think decimal representation has cohorts. If I understood the term correctly, numbers that have different memory representations (different bit patterns) but test as numerically equal belong to a cohort.

Here are some members of a cohort for decimal 2. That 14 (hex) is 20 (dec); the 4E20 (hex) is 20000 (dec). When you got the 20000, you have an exponent of 4 (actually -4) to bring the value back to 2.
00010000 00000000 00000000 00000014 2.0
00020000 00000000 00000000 000000C8 2.00
00030000 00000000 00000000 000007D0 2.000
00040000 00000000 00000000 00004E20 2.0000



This is curious and hoping someone can enlighten me. Inside a C# console app I do
Expand|Select|Wrap|Line Numbers
  1. decimal mydecimal;
  2. mydecimal=2.0m;
  3.  
and then break and look at the memory window. I diplay the address of mydecimal and it does not contain what I expect. But if I edit the value of mydecimal in the debugger, I do see the memory window show what I expect. Then I can even put in back to what it was originally and it is what I expect.

I'm trying to be articulate and struggling but here is an example. If I break right after that mydecimal assignment and I see the following in the memory window. (0x0450ecb0 is the address of mydecimal.
0x0450ECB0 00010000 00000000 00000014 ............

Then, I change mydecmal from 2 to 1 in the watch window and the memory changes to the following (which is what I expect)
0x0450ECB0 00000000 00000000 00000001

The in the watch window I change mydecimal back to 2 and see the following (again what I expect)
0x0450ECB0 00000000 00000000 00000002

What's gong on with that first display? Why don't I see what I think I should? Am I expecting the right thing? Does this have somethng to do with flushing?

Advice is much appreciated. Thanks.
-ted
Nov 4 '07 #2

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

Similar topics

1
2338
by: Riadh Elloumi | last post by:
Hi, I have some problems when debugging memory allocation (for both malloc and new) in a program that uses standard lists and vectors. When I add an element to the vector, the overloaded "delete" operator is called somewhere in the STL library and it cannot find the allocated memory. How can I avoid this problem ? Can I overload new and delete only in my code and not in the STL? You can see my problem by compiling the mem.cpp joined...
5
3686
by: Noa Garnett | last post by:
I'm developing on C++, using visual studio 6.0 with service pack 5. I have a memory corruption while debugging. Some of the variables I'm using are suddenly set to zero while progressing along the code. The specific location of the memory corruption depends on the names I give my local variables, on putting some of the codes in curly brackets - {}, and on having the watch window open. I already cleaned and re-built my project. Can anyone...
1
1185
by: Peteroid | last post by:
It looks like when I make a Form resizable and/or hit the maximize button that it shows garbage (unitialized memory) for the new portions of the form and then fills it in with background color. It only shows it very briefly, but it's VERY visible during this time. This happens with re-sizable forms too. And it 'feels' like re-sizing is 'jerky'; that is, lags a bit from my actions. I turn off visiblity to the controls on the form while...
8
1589
by: Jared.Holsopple | last post by:
Hi all, I have a dynamically allocated array of doubles in VC++ .NET. When I view the array in the watch window with "arrayName, 10", it displays the correct value for arrayName, but arrayName through arrayName are all zeros. Note that arrayName is actually double*, and not double. When I print out the array to the screen using printf, the correct (non-zero) values are displayed. I'd rather not dump a bunch of
94
4727
by: smnoff | last post by:
I have searched the internet for malloc and dynamic malloc; however, I still don't know or readily see what is general way to allocate memory to char * variable that I want to assign the substring that I found inside of a string. Any ideas?
2
21973
by: Ilkka | last post by:
I have created an C++ application with Windows Forms, ADO and SQL server 2005. Now I need to change something and started debugging the code. Then suddenly I receive an error. "An unhandled exception of type 'System.AccessViolationException' occurred in mscorlib.dll Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt." The progran ends on a windows form designer...
8
376
by: TBass | last post by:
Ok, so I'm trying to understand why my debugger can't find the memory address for the members of a structure. typedef struct ADCLIST_el { struct ADCLIST_el *pPrev; struct ADCLIST_el *pNext; void *pData;
2
2139
by: Jonathan Wilson | last post by:
I have an app written in native C++ using Visual C++ 2005 (pro edition). How can I set a memory breakpoint in the debugger for this app? Or alternatively, is there another source level debugger I can use that will let me set such breakpoints? Note that moving to Visual Studio 2008 is not an option.
22
9340
by: Peter | last post by:
I am using VS2008. I have a Windows Service application which creates Crystal Reports. This is a multi theaded application which can run several reports at one time. My problem - there is a memory leak someplace. I can not detect the memory leak by running several reports by hand, but when I run tha app as a servrice and process few hundred reports there is significant memory leak. The application can consume over 1GB of memory where it...
0
8674
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
8604
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
8895
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,...
0
8861
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6518
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
4369
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...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3046
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
2
2330
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.