- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Are there any general rules one should follow for memory allocation/deallocation to improve the efficiency of garbage collection? For example,
allocate (a(50),stat=...
allocate (b(50),stat=...
deallocate (b)
deallocate (a)
presumably works like a stack. But does it buy you anything?
Bruce Gerdes
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There's no good reason to deallocate things in a particular order.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks, Steve. "Garbage collection" was a poor description of the phenomenon I'm considering. A better term would have been "heap fragmentation.".
While I've found it practically impossible to completely avoid heap fragmentation, I've always been able to find or create waypoints in the execution at which I can defrag the heap using I/O. Between those points, however, I often find myself fragging the memory with rubber arrays. If array needs to grow, I allocate a temporary pointer for an array with, say, double the size of the original; move the original array into the new one; deallocate the original; redirect the original pointer to the new array; and nullify the temporary pointer. Quite obviously, that leaves a hole where the original array used to be.
Is there aFortran "heap manager" which recognizes the existence of this hole? It seems that there must be somesuch form of monitoring, or Fortran would apparently be incapable of reusing deallocated memory. It may not actuallyuse the hole for new allocations, but it seems that if one deallocates all the memoryabove the hole,Fortran must somehow recognizethat the top of the heap is now at thebottom of the hole.
Operating on the hypothesis that Fortran keeps some sort of heap table,it seems that the most efficientdeallocation sequence would be from the top of the heap down. To do otherwise would create additional holes and therefore additional headaches for the heap manager.
Does this make any sense? Am I overcomplicating a much simpler operation?
Bruce
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Upon further reflection, the issue may have a very short answer. That answer might be, "IFort uses malloc and free," or, "IFort uses the Windows memory management functions."
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page