Re: Freeing memory - will it be available immediately



On Tue, 26 Feb 2008 08:44:13 +0530, santosh <santosh.k83@xxxxxxxxx>
wrote in comp.lang.c:

Ian Collins wrote:

Richard Heathfield wrote:
Ian Collins said:

Kelsey Bjarnason wrote:
On Mon, 25 Feb 2008 01:10:49 -0800, karthikbalaguru wrote:

Hi,

Will 'free' return the memory Immediately to the OS ?
The proper answer is that, according to the text of the standard,
it *cannot* return the memory to the OS; the definition of free
simply does not allow this.

According to your interpretation of the somewhat ambiguous phrase
"made available for further allocation".

....which is a perfectly reasonable interpretation, and one that I
would fully expect implementors to support. (Whether my expectations
are actually met in the Real World is an entirely different matter!)

It may be a reasonable interpretation, but it isn't definitive. So
Kelsey's answer can't claim to be "The proper answer", merely one
possible answer.

A literal reading of the Standard's text supports Kelsey's
interpretation, but in practise I'd expect significantly sized
deallocations to be handed back to the OS, if there was a means to do
so.

[snip]

A literal reading of the standard's text says that allocated memory
properly free'd is made available for "further allocation". It most
certainly say "further allocation by the same program". Since the
term "further allocation" is not defined or constrained by the
standard in any way, where exactly does it forbid that further
allocation from being to another executable, process, device driver,
etc.?

As already said, Kelsey's interpretation is reasonable, but by no
means either guaranteed or required by the actual wording of the
standard.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
.



Relevant Pages

  • Re: Freeing memory - will it be available immediately
    ... The proper answer is that, according to the text of the standard, it ... available for further allocation". ... The only ambiguity in the phrase is *when* the memory becomes available ...
    (comp.lang.c)
  • Re: Freeing memory - will it be available immediately
    ... Your interpretation of "as the standard defines it" is ... Your interpretation of "for further allocation" as "for futher ... further allocation" as returning the memory to the place it came from. ...
    (comp.lang.c)
  • Re: Freeing memory - will it be available immediately
    ... Will 'free' return the memory Immediately to the OS? ... The proper answer is that, according to the text of the standard, it ... available for further allocation". ...
    (comp.lang.c)
  • Re: malloc under linux
    ... It means what it says, i.e., even if malloc returns a non-null ... memory might not actually be allocated. ... Standard even when some other process is killed and sufficient memory is ... I can't see how the Standard does not permit lazy allocation, ...
    (comp.lang.c)
  • Re: Halt execution procedure
    ... That was definitely the model for automatic in the standard. ... deallocation and then doing the new allocation that happens to find the ... The compiler also has to get some other things right in some cases, ... deallocated space available, but the "charge" against such a compiler ...
    (comp.lang.fortran)