Quote:
Originally posted by troccola
So, in a nutshell, there's no way to shrink the process size again.
|
Yow! I didn't mean to imply that. There is no way to shrink the data segment if you are using the standard malloc and free routines. To be more accurate, there is no way to shrink the data segment's virtual size. If you lay off plock(), the kernel will happily grow and shrink its physical size as required. (And by the way, repeatedly locking and unlocking segments as you are doing is guaranteed to devastate system performance if memory is tight.)
Also, you can call sbrk() directly. There is a nasty can of worms here. The direction in which the heap grows is undefined. It may grow in the same direction as the stack. Or it may grow in the reverse direction. So when you allocate a buffer you may need to return a pointer to the first new byte or the last new byte. This can change from system to system. So you will want your own routine that sits on top of sbrk to hide the idiosyncrasies of pointer arithmetic from the application. And be aware that this routine cannot be written portably.
And using the stack is another way processes grow and then shrink. Automatic variables spring into existence when a function is called and vanish when it returns.