Winsk said:
how to find out how much memory is blocked(or has been allocated
to a pointer).
consider,
int *p=new int;
or
int *p=new int[100];
Both are syntax errors. I suspect you're slightly lost. Were you looking
for comp.lang.c++? Still, stick around, because this is a common C
question too, albeit with...
suppose i dont know the right hand side of the statement i.e.
new int or new int[100] or new int[n] (where n is calculated during
runtime)
.... p = malloc(n * sizeof *p) rather than p = new int[n], but it's the same
deal really.
(definitely sizeof(p) would not give me the amount of memory
allocated.)
Right.
i would be interested in knowing the amount of memory taken up by the
respective pointers in a program. how could i possibly achieve this?
See that n? At the time you're allocating the memory, you do actually know
how much memory you are allocating. If you will need this information
later, Don't Forget It! Store it somewhere.
Are there any methods or standard routines to measure the amount of
memory?
Remembering, at the time you allocate.
If there are no standard methods or routines why would this be so ?
Because it's so easy to remember, at the time you allocate.
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999