Click here to Skip to main content
15,921,062 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All

Is there any way to get that how many bytes is being consumed by a structure member, by looikng at its address at debug time.
for example-
i have a struct strt1 its one of member is a1 now address of strt1->a1 is
0x00fe4984
can we calculate the size this member is carrying?

i am sorry if its a silly problem but i could not calculate its size :(
Posted

If you have the source it is trivial. Use sizeof on the dereferenced structure address. But I suppose you are asking when you don't have the code.

The only way to get the size of the structure is to analyze the memory content. Even there you must have a fair bit of idea to separate the "junk" from the data. In debug mode, certain memory addresses seem fixed and things get loaded there quite frequently. If you can, first get to know the address after a few dummy debugs. Then load a dummy array of a suitably large size in that area, delete it and then load this structure in that area. The extra CD (or whatever) bytes must be able to help separate "junk" from the structure's data. This isn't fool proof since the data of the structure might coincide with the bytes.

Yet, in spite of these efforts, all you will get to know is the size of the entire structure. I mean you won't be able to make out if the structure has an array of eight characters or four shorts or two integers or just a double. It isn't impossible but you have to do a lot of dirty work in decoding the raw bytes.
 
Share this answer
 
Size of the member?? No. That's like trying to judge the size of a house by simply looking at it's street number. Can't be done.
 
Share this answer
 
If the structure has been allocated dinamically (i.e. through a call to malloc or new), you can use the _msize (CRT)[^] function to get the size of the allocated memory block; however that could not be the size of the structure (e.g. if you use it on the pointer obtained by calling new MyStruct[10] what you get is sizeof(MyStruct) * 10).

Anyway, why couldn't you use the sizeof operator?
 
Share this answer
 
v2
i donno why u want to do that,

try using sizeof() function if you want to get the size.

Also in the debug , u can use the quickwatch window , to check the size.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900