S
sh.vipin
is there any way to find out number of bytes freed on a particular
free() call in C
free() call in C
is there any way to find out number of bytes freed on a particular
free() call in C
(e-mail address removed) said:
When you allocate this storage, you know how much storage you allocated.
Don't Forget.
Then, when you come to free it, you know, right?
--
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
yea but then i will have to store this information (number of bytes
allocated) at the time of allocation. so also a link between a pointer
and number of bytes it is linked with ...esentially i don;t want to
write my own memory allocator.
The only portable way is to store that information when you initially
allocate the memory (and update it if you subsequently successfully
call realloc using that pointer). If you want non-portable ways, you
could try asking in a platform specific group. Even there, it may
depend on what specific standard library implementation you are using,
and may simply not be available by any means.
-David
is there any way to find out number of bytes freed on a particular
free() call in C
yea but then i will have to store this information (number of bytes
allocated) at the time of allocation. so also a link between a pointer
and number of bytes it is linked with ...esentially i don;t want to
write my own memory allocator.
(e-mail address removed) said:
When you allocate this storage, you know how much storage you allocated.
Don't Forget.
Then, when you come to free it, you know, right?
Walter Roberson said:When the free() call is made, all of these overhead bytes and
extra bytes are freed -- so the number of bytes freed does not
necessarily match the number of bytes allocated.
is there any way to find out number of bytes freed on a particular
free() call in C
Not portably.
Usually you don't need to know; free frees what malloc malloced.
What is it that you'd do with the answer, were you to have it?
--
'It changed the future .. and it changed us.' /Babylon 5/
Hewlett-Packard Limited registered no:
registered office: Cain Road, Bracknell, Berks RG12 1HN 690597 England
i am writing a simple application where i want to keep track of number
of bytes my process is using currently or peak memory used by my
process so far.
i am writing a simple application where i want to keep track of number
of bytes my process is using currently or peak memory used by my
process so far.
i can modify xyz_mallo() to solve this problem such that when asked to
allocate N number of bytes, allocate N+1 and return pointer to the 1st
onwards (not 0th) byte as a new memory to aplication and in first byte
store the number of bytes allocated. but it might cause serious
alignment problem
i am writing a simple application where i want to keep track of number
of bytes my process is using currently or peak memory used by my
process so far.
yea, probably my problem is not hard enough to require a memory
manager to be written. probably there must be some API to tell me
current memory usage.
Richard Heathfield said:Walter Roberson said:
True, but not particularly important in the grand scheme of things as far
as the abstract machine is concerned.
On 8 Aug 2008 at 15:02, (e-mail address removed) wrote:
There is, of course, but the people here will swear blind it doesn't
exist with all the fervor of a madman claiming the sky is not blue.
Walter Roberson said:There are a lot of times that the sky is not blue. Like when it is
night out. Or when there are heavy clouds. Severe weather such as
close approximations of torados can turn the sky *very* strange
colors -- as can some kinds of severe snow storms.
"the sky is blue" is not a portable assumption.
Bartc said:So what colour is 'sky blue'?
yea but then i will have to store this information (number of bytes
allocated) at the time of allocation. so also a link between a pointer
and number of bytes it is linked with ...esentially i don;t want to
write my own memory allocator.
Serve Lau said:You dont have to. You can store the number of allocated bytes without
have to introduce a new type.
void *my_alloc(size_t n) {
void *pv = 0;
if (n > 0) {
if ((pv = malloc(n + sizeof(size_t))) != 0)
*(size_t *)pv = n;
}
return (pv != 0 ? ((size_t *)pv) + 1 : 0);
}
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.