Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!zaphod.mps.ohio-state.edu!wuarchive!uunet!glyph!ahh From: ahh@glyph.kingston.ny.us (Andy Heffernan) Newsgroups: comp.sys.amiga.programmer Subject: Re: Memory fragging Message-ID: <1600@glyph.kingston.ny.us> Date: 26 May 91 02:46:54 GMT References: <1991May21.195251.16477@zorch.SF-Bay.ORG> <21795@cbmvax.commodore.com> <1991May23.114423.11039@medar.com> <21838@cbmvax.commodore.com> Reply-To: ahh@glyph.UUCP (Andy Heffernan) Organization: Moji Computing Lines: 31 In article <21838@cbmvax.commodore.com> peter@cbmvax.commodore.com (Peter Cherna) writes: >In article <1991May23.114423.11039@medar.com> jseymour@medar.com (James Seymour) writes: >>But if you eventually F/free() the other two, the three chunks of memory >>(in the above example) will be coalesced by the o/s, won't they? > >I'm not a fragging expert, but I've always assumed the system was >happier if you tried to free things in reverse order. (Intervening >processes may make allocations.) It's also a generally good programming >practice. Well, sorta. For your typical coalescing memory allocator, given that the heap starts out unfragmented at time t1, and -all- allocations/frees are perfectly nested until time t2, there will be no fragmentation in the heap at any point between t1 and t2. It's not really a heap anymore, it's a stack. Given that nearly all allocations on the Amiga come from the common system heap (AllocMem/FreeMem), however, maintaining perfect nesting of allocations is clearly impossible. Performing allocations from a per-process memory pool (a la sbrk()/malloc()) allows a process total control over its heap and helps to localize any eliminate fragmentation. At any rate, if between t1 and t2 (same initial conditions as above), n random tasks madly allocate and free memory from the system heap in any order, but all memory is guaranteed to have been freed by t2, there should be no fragmentation at time t2. If there is, either the coalescer has a bug or not everything has actually been freed. -- ------------------------------------------------------------------------- Andy Heffernan 文字 uunet!glyph!ahh