On Sun, 09 Nov 2003 07:45:43 GMT
Freejack <us**@nospam.net> wrote:
<snip>
It's my understanding that the OS leaves the memory mapped to the
programs heap(or storage pool) and then draws from that pool for any
new malloc calls.
That is a common way to implement it, however it is not required to do
that.
It's my understanding that the sequence works like this mmap()
malloc()[mlock() | munlock()] free() munmap()
So the only way to garauntee that the memory is reclaimed by the OS is
to unmap it after calling free().
mmap, mlock, munlock and munmap are off topic since that are not part of
ISO C, however...
If you are using malloc to obtain memory then it won't be obtained from
memory *you* have mmap'ed. If you munmap memory that was malloced then
freed you are quite likely to crash you program since if it was not
mmap'ed (you don't know whether it was) that it is probably an invalid
operation and if it was mmap'ed then because you have gone behind the
implementations back it may well return you a pointer to the memory you
unmap'ed without having re-obtained the memory from the OS.
In other words, DON'T mix the system specific calls and the ISO C
library calls on the same objects.
I would suggest using malloc/free unless you have performance issues
which a profiler shows are due to the overhead of malloc/free, then
consider whether you can use malloc/free in a more efficient manner (say
by mallocing memory in larger chunks) and only as a last resort change
to using system specific calls.
--
Mark Gordon
Paid to be a Geek & a Senior Software Developer
Although my email address says spamtrap, it is real and I read it.