Memory allocation/deallocation for tree? Any good way?

Tim McDaniel mcdaniel at adi.com
Thu Jan 10 02:21:48 AEST 1991


fangchin at portia.Stanford.EDU (Chin Fang) writes:
   From what I understand, if my malloc(3C) and free3(C) work
   correctly, as long as I make sure that a sequence of malloced
   memory blocks are freed in EXACTLY the reverse order, my program's
   memory consumption would stay constant no matter how many
   iterations it goes thru.

There are no firm guarantees.  A free() that did nothing would satisfy
ANSI C, and there are certainly no guarantees in non-ANSI C.

In most implementations, if the requests are all the same size, it
doesn't matter in what order the blocks are freed.  Choose any
convenient order.

If the size of your program is growing, it may not be your fault.
Many standard libraries do their own dynamic storage allocation.

There are libraries that check for memory allocation "leaks" (cases
where you malloced a block and neglected to free it.)

--
Tim McDaniel                 Applied Dynamics Int'l.; Ann Arbor, Michigan, USA
Work phone: +1 313 973 1300                        Home phone: +1 313 677 4386
Internet: mcdaniel at adi.com                UUCP: {uunet,sharkey}!amara!mcdaniel



More information about the Comp.unix.questions mailing list