Mail Archives: djgpp-workers/2002/05/17/05:00:42
> Date: Thu, 16 May 2002 14:50:13 -0400
> From: CBFalconer <cbfalconer AT yahoo DOT com>
> > How do you overcome the problem of joining non-contiguous chunks?
> If the various sbrk calls returned something non-contiguous (the
> unexpected returns) nothing can join those.
I didn't mean memory that was non-contiguous to begin with. I meant
memory that was returned as contiguous by sbrk, but was then
subdivided into chunks by malloc, and became non-contiguous after
several allocations and deallocations.
> However everything in a contiguous sbrk chunk, whether created by
> one or several sbrk calls, will be rejoined when all components are
The problem is precisely that not everything is deallocated when you
suddenly need a large chunk of memory. Some Lisp objects are
short-lived, others tend to live for a long time before they die and
are freed by the garbage collector. That's the reason for
The only way to avoid the adverse effects of such fragmentation is to
relocate memory when you don't have a contiguous block large enough to
satisfy the request, but do have enough free memory in non-contiguous
chunks. That's what the Emacs relocating allocator does, but that
cannot be done in a C library.
> nmalloc keeps track of adjacent allocations and rejoins them
> when freed. Adjacent free blocks are always joined into one larger
> block. It also attempts to do any new allocations from the free
> space list on something close to best fit, and avoids sbrk calls as
> far as possible.
I think the current libc version also does that, at least within the
- Raw text -