can I know the amount of memory freed by call to free 
Author Message
 can I know the amount of memory freed by call to free

Hi
If I call free with like this
free(p);
p is declared as char *p;
Can I determine the memory freed by it
Thanks


Sat, 23 Oct 2004 11:28:57 GMT  
 can I know the amount of memory freed by call to free

Quote:

> If I call free with like this
> free(p);
> p is declared as char *p;
> Can I determine the memory freed by it

No.


Sat, 23 Oct 2004 11:58:28 GMT  
 can I know the amount of memory freed by call to free


Quote:
> Hi
> If I call free with like this
> free(p);
> p is declared as char *p;
> Can I determine the memory freed by it

Yes. It frees the memory that p pointed to, which is as big as it
was when you allocated it. If you need to know how big that is later,
you have to arrange to remember it.

--
Chris "or not to need to know, which is preferable" Dollin
C FAQs at: http://www.faqs.org/faqs/by-newsgroup/comp/comp.lang.c.html
C welcome: http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html



Sat, 23 Oct 2004 18:09:25 GMT  
 can I know the amount of memory freed by call to free


Quote:
> Hi
> If I call free with like this
> free(p);
> p is declared as char *p;
> Can I determine the memory freed by it

I you write your code that way.

#include <stdio.h>
#include <stdlib.h>

int main()
{
    size_t sz = 1000;
    char *p = malloc(sz);
    if(p)
    {
        /* do stuff */
        free(p);
        printf("%lu bytes of allocated memory released\n",
               (unsigned long)sz);
    }

    return 0;

Quote:
}

-Mike


Sun, 24 Oct 2004 03:15:59 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Silly way of getting amount of free memory

2. Q: amount of free + used memory

3. how does free know how much to free

4. how does free() know how much to free?

5. how free realy frees memory ?

6. Problems freeing memory using "free"

7. how to know the free memory

8. I am seachcing a free pascal editor if someone known a web site just called me

9. freeing memory after a (char *)function is called

10. Does CString require manual call to free memory

11. Amount of free conventional RAM

12. How to find out amount of free resources (gdi resources, handles, system resources)

 

 
Powered by phpBB® Forum Software