Re: memory not freed up?
- From: Rich Townsend <rhdt@xxxxxxxxxxxxxxxxxxx>
- Date: Fri, 28 Oct 2005 11:23:40 -0400
fj wrote:
This seems simple but it is not !
The problem probably comes from the global use of the computer memory. Languages like C and F90 allocate fixed parts of the memory. Then, when a lot of allocate/deallocate (or malloc/free) instructions are performed, then the memory becomes a sort of chain, ramaining allocated objects being separated by holes (memory deallocated previously). When allocating a new large amount of memory, the compiler has to choice between selecting a zone which has never been allocated before, or finding a hole just large enough to contain the requirement.
By experience, (I wrote a long time ago a library to manage memory in F77 programs), finding a hole may be an expensive task. So, sometimes, holes become dead zones especially if several independent programs are running together.
In my library, I decided to make possible to move arrays from time to time in order to suppress dead zones. But such a technique assumes a double pointer association, the "pointer" managed by programs pointing to the address of the address of the memory zone. Then, moving a memory zone does not change the first address (only the second one).
In a language like JAVA, the garbage collector is authorized to move objects. This is one of the reasons which make the coupling java->C or java->Fortran not obvious.
Can I suggest a much-simpler strategy to avoid memory fragmentation: always try to deallocate arrays in the order in which they were created. As far as I'm concerned, any approach more sophisticated than that will be highly platform-dependent, and therefore may have sub-optimal performance on platforms for which it was not 'tuned'.
cheers,
Rich .
- Follow-Ups:
- Re: memory not freed up?
- From: Brooks Moses
- Re: memory not freed up?
- References:
- memory not freed up?
- From: cluenewbieblue
- Re: memory not freed up?
- From: fj
- memory not freed up?
- Prev by Date: Re: Large code projects [Was: equivalencing a charactor string array to a double array]
- Next by Date: Re: complex arithmetics
- Previous by thread: Re: memory not freed up?
- Next by thread: Re: memory not freed up?
- Index(es):
Relevant Pages
|