At 12:04 on 6 February, Peter Shenkin wrote:
> Fortran "deallocate()", like C's "free()", rarely actually
> returns memory to the OS. Thus, program memory, when
> observed using an external tool, will not decrease; it
> will only increase. The freed memory remains associated
> with the process and is availble for re-use the next time you
> "allocate()" an object.
>
> Of course, the above is OS- and implementation-dependent;
> language standards don't dictate how the OS handles memory.
> But it's nearly always true under UNIX, at least.
>
> In part this is a time optimization: it's expensive to go
> out to the OS to ask for more memory. So if a subsequent
> "allocate()" can satisfy its request locally, the operation will
> be much faster.
>
> If you really need to access, then release memory, consider
> the use of the POSIX mmap/munmap routines.
Another approach is to do your own garbage collection. Instead of
deallocating a node you have finished with, attach it to a linked list
of free nodes. You can attach a whole linked list to the free list
just as easily as a single node. Then when you next need a new node,
take one off the free list, only allocating a new node if the free
list is empty.
--
Anthony Stone http://www-stone.ch.cam.ac.uk/
University Chemical Laboratory, Email: [log in to unmask]
Lensfield Road, Phone: +44 1223 336375
Cambridge CB2 1EW Fax: +44 1223 336362
|