> (sorry if this is a duplicate - weird error message from Mozilla last
> time, when I tried 'Reply All')
> I took a look at the man page, and
> 1. Found disclaim on AIX, but not Linux.
> 2. Found another function, munmap(), that looks similar and is present
> on both systems.
> 3. Man pages talk about shared memory, and reference the shmat function
> in their 'see also' sections.
> So, is it okay to use munmap() and is it okay to use either of these
> functions for plain malloc'd memory?
> If so, do you call munmap() instead of free() or after calling free()?
No, munmap() won't do what you want. Quoting from the AIX 4.3 man page:
"The munmap subroutine unmaps regions created from calls to the mmap
What you want to do involves the computer science problem known as
garbage collection. I'm sure there are many computer science texts
that will outline possible solutions to this problem. The problem arises
because, as you malloc() and free() memory, the heap becomes fragmented.
The O/S has no clue as to how much of the heap is actually in use,
so there is no way for the system to automatically shrink the heap.
The brk()/sbrk() library functions might do what you want. They
change the size of the process data segment. In fact, I believe that
malloc() calls brk() to extend the data segment as necessary.
However, if you are going to do garbage collection, do it carefully,
or you might end up releasing memory that's in use back to the system.
The next time your program attempts to use that released memory,
you'll get a segmentation violation.