Subj : Re: malloc() To : borland.public.cpp.borlandcpp From : Bob Gonder Date : Thu Jun 24 2004 08:53 pm Ed Mulroy [TeamB] wrote: >While I also try to free the last malloc'd (or delete the last new'd) >item first, I have never found anything that shows why that is better. >I just assume that it is better to do it that way. I think, back in the early BC days, as I was learning C, that I had fragmentation issues with FIFO free. IOW if you allocate regions 1,2,3 then release 3, 3 would see that 4 was free, and add itself to 4. Then if you released 1, there would be no other chain to add to, so it would remain small. Releasing 2 next would add 2 to 3/4, but didn't go "down" the chain and reclaim 1. That's when I moved back away from dynamic allocation (never used it in ASM prior). As for the Window API having the same problems..Yes, with miswritten code, there can be data corruption, but I'm pretty sure Windows will free the buffer just fine, as I believe the "links" are in the OS, and not the user space. But then I prefer static (preallocated) and/or stack variables to runtime allocated ones. .