Re: Doubts about free()



Assuming there is a need for memory by some other process and no other
free memory is available, is it the case malloc for the other process
would fail under such circumstances. Does the OS do some kind of
tracking and free up this memory. Is there any way to force freeing up
the memory to the system back.

I don't think that managing memory in that way is a program's job. You
just have to allocate memory (malloc) and release it (free). The
implementation specific details shouldn't bother you, unless you are
writing specialized program that requires good performance and uses
many resources.

In such kind of implementations which does not release pages of memory
allocated by the program, pages full of "empty and reserced" blocks
probably will be swapped, and there won't be any problems with
allocating memory for other processes.

If you want to get on the lower level of managing memory, you will
need to write your own implementation of malloc/free functions.
However, then you need to use platform dependent functions such as
sbrk in POSIX.

Pawel Dziepak
.



Relevant Pages

  • Thank You -- Thomas J. Gritzan
    ... Thomas -- Your suggestion to malloc() out a block of memory was the ... Below are some details of my memory issues ... ... As a work around solution I guessed a ram disk would solve the ... persistence will frustrate the off topic police and give them a target ...
    (comp.lang.c)
  • Re: Dynamic Allocation Problem...
    ... The only legitimate failure from malloc() is a NULL pointer, and, ... > mallocto allocate memory for the Pointer variables. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: C + Malloc
    ... No need to cast malloc(). ... You need to _either_ allocate memory ... you have in fact created a memory leak. ... memory for ptr to point at. ...
    (comp.lang.c)
  • Re: Simple question about headers and malloc!
    ... Therefore I am making all of its declarations ... memory (using malloc) and then exit back to main. ... allocation, I get data strored from the second allocation... ...
    (microsoft.public.vc.language)
  • Re: Is correct ?
    ... When you want to allocate memory dynamically, you call malloc. ... When you have finished with the storage, ...
    (comp.lang.c)