![]() |
How to know how much memory is the object is using..
Hi,
Lat us take a class like Code:
class AMy question is how to know how much memory is the object actually dealing with.. i mean in this case 2pointrs = 8 bytes memory allocated for i = 50 * 4 = 200 bytes for c = 100 bytes In total 308 bytes.. Is there any function we can use to get this 308 as the answer... If we are creating some other objects in this class, then that memory also has to include.. |
Re: How to know how much memory is the object is using..
You should learn to use Code blocks. See the FAQ
|
Re: How to know how much memory is the object is using..
Yes you are right... Only 8 bytes will be..
Code:
#include<iostream.h> |
Re: How to know how much memory is the object is using..
You can't use sizeof because i and c are dynamically sized and therefore not known until runtime, so you would have to write your own custom size function.
If i and c are statically sized then you can use sizeof. Code:
class A |
Re: How to know how much memory is the object is using..
Right solution!!!
By any way You can'nt overload sizeof operator ..So Your solution is nice one... Better If You will take care of all cases. At any time object size can be increased as it depends on ilen and clen as you have taken variables.. Now you have to make accesors function like upDateiLen() and GetiLen() upDateilen() function should taking care of updated values of ilen means called each time when i = new int[ilen]; called and by Getilen() function het the updated value of ilen var. Do same for clen var also. |
Re: How to know how much memory is the object is using..
Trueth -> Truth
Can'nt -> Can't. Truth can't be changed, but spelling can be improved. |
Re: How to know how much memory is the object is using..
Quote:
By any way all over my English is not so good... Thanks for reminding me to alert about spelling... Thanks a lot.. |
Re: How to know how much memory is the object is using..
Thank you ansari.. I really don't know that sizeof() will work at compile time... and thank you xpi0t0s for the solution given.. I thought there may be some pre defined function which can do this for us..
Thank you Shabbir.. so far I didn't heard about Code Blocks IDE... I will look into it... |
Re: How to know how much memory is the object is using..
I was talking about - http://www.go4expert.com/misc.php?do=bbcode#code
|
Re: How to know how much memory is the object is using..
:) I thought Code Blocks IDE..
From next time onwards if I am posting code I will fallow the code blocks menctioned... |
| All times are GMT +5.5. The time now is 18:07. |