[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]

Re: Re : [LI] free...



Mahendra M wrote:
> 
> Hi,
>         Arun K Desai wrote:
> 
> >What "free" does???Suppose i am having a pointer say *ptr.
> >If say free(ptr) what it does???
> >If say  ptr=NULL what it does???
> >Is it both are same????

if you say ptr=NULL the ptr will not point to anything but the
memory allocated via malloc() (or alloc or calloc or ...) will
be lost i.e. no other program will be able to use it. It does
happen a lot in real life and is the major cause of memory leaks
in programs...

free deallocates the memory allotted so that the memory allocated
via malloc() can be reused


-VK

> 
> free : frees  the  memory  space pointed to by ptr, which
> must have been returned by a previous  call  to  malloc(),
> calloc()  or  realloc().   Otherwise,  or if free(ptr) has
> already been called before,  undefined  behaviour  occurs.
> If ptr is NULL, no operation is performed.
> 
> -Mahendra M
> RV College of Engineering, B'lore.
> --------------------------------------------------------------------
> The Linux India Mailing List Archives are now available.  Please search
> the archive at http://lists.linux-india.org/ before posting your question
> to avoid repetition and save bandwidth.

-- 
---

Vivek Kumar
(x49049)
--------------------------------------------------------------------
The Linux India Mailing List Archives are now available.  Please search
the archive at http://lists.linux-india.org/ before posting your question
to avoid repetition and save bandwidth.