I have found that excessive use of realloc() causes memory
As an example, I have a program that uses a rotary buffer (about 400
elements deep). Each element starts at 32 bytes, but more memory
is realloc()ed as needed. This realloc happens slowly (sometimes 2
bytes at a time), and the buffers can sometimes exceed 1024 bytes.
Since I'm using a rotary buffer, each element would eventually get
flushed and restart at 32 bytes. Therefore the program should
eventually reach a "high water mark" in memory usage, and never
go beyond that. Unfortunately, after adding fragmentation to the
equation, this ends in a program that keeps chewing more memory until
the OS crashes!
The best solution I've been able to come up with is to replace the
realloc()s with a malloc, memcpy, and free. So instead of just
trying to expand, or shrink the memory block in its spot, the block
will actually be reallocated, hopefully filling in the memory gaps.
I've been told the QNX4.24 will have better memory management.
Has anyone else come up against this problem? Does anyone have a
"If you're looking for trouble, you've come to the right place!"
www: http://www.anca.com.au, http://www.netlink.com.au/~zanettin