"jacob navia" <> wrote in
<bhjdml$tvi$>:
>
>"Mark A. Odell" <> wrote in message
>news:Xns93D8973EFDD1FiiiCopyrightMarkOdelliii@130 .133.1.4...
>> (sbayeta) wrote in
>> news: om:
>>
>> > Hi,
>> > I'd like to know who is responsible of memory recycling and
>> > defragmentation in a C/C++ program, assuming all the memory
>> > allocation/deallocation is done using malloc/free or new/delete.
>>
>> There is no C/C++ language. There is C which we discuss here. So from a C
>> point of view there is no automatic memory recycling.
>
>Wrong.
So, if automatic memory recycling is a built in feature of
standardized C, what was this "Garbage Collection in C" thread
good for then?
>
>If I write:
> int fn(void) {
> char *a = malloc(100);
> free(a);
> return 0;
> }
>
>I expect that a reasonable implementation recycles the memory the best it can and my memory
>consumption doesn't increase exponentially, sorry. I suppose that if I free a pointer, the memory
>will be RECYCLED by the malloc/free system and the total memory consumption will not increase.
Maybe. Maybe not. You're expexting, guessing, supposing. What if
I'm just about to finish a conforming C implementation that
physically burns free()'d memory for security reasons? Is this
impossible?
[OT]
And please, please cut down your line length, your posts are
messing up my newsreader...
0 1 2 3 4 5 6
01234567890123456789012345678901234567890123456789 01234567890123456789
[/OT]
>
>Of course I know that many implementations of malloc/free do not actually return the RAM to the OS
>but recycle it for new requests. This is also a recycling strategy, sometimes more efficient
>sometimes not.
So, who is responsible for reclaiming free()'d memory then?
>
>But to say that there is no recycling in the malloc/free cycle (pun intended) is WRONG. If there was
>no recycling why would we bother to call free() ?????
To let the implementation do whatever it does with free()'d
memory...
>
>
>> You malloc() the
>> memory and you must free it properly when done with it.
>
>Yes. To be able to recycle it of course!
See above. Maybe it's recycled for further use. Maybe not.
(Whereas you're right in that *probably* *most* implementations
will do so.)
>
>> If this
>> process fragments memory over time, it's too bad as C does not do any
>> garbage collection.
>
>I would be surprised that the algorithms (known for decades) to avoid fragmentation wouldn't have
>gotten into many malloc() implementations. They are quite sophisticated beasts. Of course it depends
>of the quality of the run-time library, but most of them are very good quality stuff. Gcc for
>instance has a quite good library.
Right, *many implementations* will do so. Got the point?
>
>Look Mark. There was recently a discussion (that I started, provocatively as a "spam" message 
>about the GC.
>Now this question touches the same thema again, and you feel that the wrong party line is
>insinuating somewhere.
Starting it all over again... *g*
>
>And you loose control Mark. You say nonsense. How can you imagine that there is no recycling in C? I
>mean those are the very basics.
IMHO Mark is perfectly right. You are the one who's generalizing
the behaviour of some implementations to be the one and only way
to do things. Basically, I *can* imagine C without memory
recycling. ( Maybe there's a lack of imaginational potential on
your side? *g* )
Ooooops, I just stumbled over this (from the N843 draft):
-----
7.20.3.2 [...] [#2] The free function causes the space pointed
to by ptr to be deallocated, that is, made available for
further allocation.
-----
Maybe I was totally wrong
That's why I call for the experts now - please help.
Irrwahn
--
If you can see it and it’s there - it’s real.
If you can’t see it, but it’s there - it’s transparent.
If you can see it but it isn’t there - it’s virtual.
If you can’t see it and it isn’t there - it’s gone.