Re: Freeing memory - will it be available immediately
- From: Kelsey Bjarnason <kbjarnason@xxxxxxxxx>
- Date: Tue, 26 Feb 2008 09:26:11 -0800
[snips]
On Mon, 25 Feb 2008 21:53:43 -0600, Jack Klein wrote:
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".
I assume you meant "does not say" there.
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.?
The C standard defines the expected behaviour of a C program.
The C standard, in order to do this, also defines the expected behaviour
of the standard library functions, behaviours on which that C program can
rely.
The C standard defines free as releasing the memory to be made available
for further allocation.
That's the defined operation _in the context of defining the operation of
a C program and the standard library on which it relies_. There is
nothing in that definition which allows for any other behaviour, such as
handing the memory back to the OS.
Nor, as noted elsewhere, does the "as-if" rule give us an out; failure to
make the memory available for further allocation (eg by giving it back to
the OS) is a direct violation of the text of the standard and cannot come
under the as-if rule; the as-if rule allows flexibility in conforming
behaviour, it does not allow non-conforming behaviour to take the place
of conforming.
Let's turn this on its head. You say "It most certainly does not say
'further allocation by the same program'". Very good. Explain, then,
exactly what the standard is defining the behaviour of, *if not the very
program under discussion*?
Of course it's defining the behaviour of the program and only the
program; it has no ability to define behaviours beyond that. It cannot
mandate that the system actually use a hard disk, or a monitor, it cannot
mandate that "text mode" universally means using "\r\n" so any other
applications or OSen better wake up; it defines one thing and only one
thing, the behaviour of the C program written against that standard.
In order to do so, in order to define the behaviour of the C program, it
*also* has to define the behaviours of the standard library, on which the
C program may rely. It does so, in the case of free: the memory is made
available for further allocation.
Not to the OS, not to your toaster oven, not to some other program, the C
standard has nothing to say on these matters. No, the only thing under
examination, the only candidate which the standard *can* define such
behaviours for, is the C program. It defines just such a behaviour, for
that program, and that definition absolutely precludes the notion of
handing the memory back to the OS; doing so violates the defined
behaviour of free.
.
- Follow-Ups:
- Re: Freeing memory - will it be available immediately
- From: Herbert Rosenau
- Re: Freeing memory - will it be available immediately
- From: Walter Roberson
- Re: Freeing memory - will it be available immediately
- References:
- Freeing memory - will it be available immediately
- From: karthikbalaguru
- Re: Freeing memory - will it be available immediately
- From: Kelsey Bjarnason
- Re: Freeing memory - will it be available immediately
- From: Ian Collins
- Re: Freeing memory - will it be available immediately
- From: Richard Heathfield
- Re: Freeing memory - will it be available immediately
- From: Ian Collins
- Re: Freeing memory - will it be available immediately
- From: santosh
- Re: Freeing memory - will it be available immediately
- From: Jack Klein
- Freeing memory - will it be available immediately
- Prev by Date: Re: Freeing memory - will it be available immediately
- Next by Date: Re: Question regarding UB
- Previous by thread: Re: Freeing memory - will it be available immediately
- Next by thread: Re: Freeing memory - will it be available immediately
- Index(es):
Relevant Pages
|