Thanks for the Reply...yeah this was my Question... :)
On Tue, 2009-11-10, peter koch wrote:
On 10 Nov., 06:37, mithun <mithunsi...@gmail.com> wrote:
Hi,
In the following code snippet ....
#include<stdio.h>
#include<iostream>
using namespace std;
class A
{
int a,b;
char c,d;
};
main()
{
A *a = new A();
cout<<"\n"<<sizeof(a);
}
The following code gives output 4 as 'a' is pointer. I want to get the
complete size of object allocated ie 10. How can this be done.
I would guess sizeof A to be 12, not 10. It is trivial to get the size
of an A, but that does not give the size of the memory allocated. At
least sizeof A bytes will be allocated, but it could easily be more -
12, 16, 24 and 32 would be probable numbers.
It is also possible that "mithun" wanted something even more general:
memoryuseof(*a);
memoryuseof(std::string("foo"));
memoryuseof(std::vector(42, *a));
finding out how much "heap space" an object uses, including memory
pointed to.
(Such a thing doesn't exist, I think. Certainly not in the language.)
/Jorgen
--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .