Re: Freeing memory - will it be available immediately



Kelsey Bjarnason <kbjarnason@xxxxxxxxx> writes:

[snips]

On Fri, 29 Feb 2008 11:39:26 +0000, Ben Bacarisse wrote:

I have been sitting on my hands with this thread, but I can't any
longer. Your basis for this is that the standard only considers one
program, that there is no "OS" so how else can one interpret "being
available"?

No, that's not my basis; check the thread.

Earlier you did seem to stress the fact that the standard does nothing
but define the behaviour of one program -- that any discussion of
other entities was reading more into the words than could be there.
But I am very happy if you are not saying this. The word "allocate"
suggests exactly this: the presence of multiple entities that own the
memory -- initially something other than the program, and then the
program, once malloc has succeeded.

You miss the fact that there *is* another entity here, but only by
implication. It seems reasonable to me to interpret "available for
further allocation" as returning the memory to the place it came from.

And nobody said anything about "to the place it came from".

malloc does not create the memory, it "allocates" it.

Yes, and?

It can't be a debate if you do this sort of thing. The "and" comes in
the conclusion I draw in the very next sentence.

This implies a
sort of change of ownership from some other entity (the OS, of course)
to the program.

Assuming there is an OS; there need not be.

I said "entity". I apologise for the parenthetical OS reference. The
word "allocate" can be taken to be a change of ownership. That is the
point. "To assign" and "to allot" are similar.

An allocation is an assignment, from one entity to
another. Making memory "available for further allocation" could be
taken to mean the memory reverts to the state (of ownership) that it had
before.

it could be, except that the standard forbids it. The defined behaviour
of free is the defined behaviour of a C standard library function as
relied upon by a C program. The definition of that function, upon which
the program relies, says that the memory *is* made available for further
allocation. Not "may be, if the OS hasn't handed it off somewhere else",
and there is *no* clause for such implementation-defined behaviour
anywhere in the definition.

Was the memory "available for allocation" before malloc allocated it
to the program? I see that as a perfectly reasonable meaning for
those words. For free to do no more than re-create that state of
affairs seems equally reasonable. It withdraws the ownership
previously granted.

I can accept that you don't, but I am finding it hard to see why you
think it is unambiguous.

--
Ben.
.



Relevant Pages

  • Re: A solution for the allocation failures problem
    ... Can you find anything in the standard which *allows* this behaviour? ... it defines how your C program is supposed to behave. ... previously allocated memory available for further allocation. ... says the memory will be made available for further allocation. ...
    (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 ... Except that this ignores the very reason for the standard, ... return the memory back to the OS in the manner you describe. ...
    (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: calloc/free: a preplexing observation
    ... > that any program that writes to stdout can be strictly conforming): ... > whether lazy allocation is conforming or not, ... > The requirement for mallocis that it has to behave as the standard ... > recursive function call attempts to allocate a terabyte of memory, ...
    (comp.lang.c)
  • Re: How to release heap memory that is marked as free
    ... As I said, fragmentation is a very serious problem, and one of the most serious problems ... my allocator was accused of using massive amounts of memory. ... I'm going to have to re-think the memory allocation that I'm ... process's 'working set'. ...
    (microsoft.public.vc.mfc)