"High water" Memory fragmentation still a thing?

Steven D'Aprano steve at pearwood.info
Mon Oct 6 09:20:12 CEST 2014


On Sun, 05 Oct 2014 20:23:42 +0100, mm0fmf wrote:

> On 04/10/2014 02:02, Steven D'Aprano wrote:
>> Way back in the mid 1980s, Apple Macintoshes used a memory manager
>> which could move memory around.
> 
> But the memory manager didn't return a pointer to memory the way malloc
> does. It returned a pointer to the pointer and you had to double
> dereference it to get the heap address (ISTR, 30 years ago now).

Correct.


> The
> advantage being the memory manager could shuffle the memory about and
> update the pointers. Your pointer to a pointer would still point to the
> same block after a shuffle. Of course you couldn't hold on to a partial
> dereference across system calls... can you guess why? :-)

Because system calls might trigger a memory compaction or move.


Before the move, you have a managed "pointer to pointer" (handle) 
pointing to a managed point which points to a block of memory:


handle -----> pointer -----> "Some stuff here"

Grab a copy of the pointer with a partial deref:

myPtr := handle^;  (*I'm an old Pascal guy.*)


So we have this:

handle -----> pointer -----> "Some stuff here"
myPtr -----------------------^


Then you call a system routine that moves memory, and the memory manager 
moves the block, updating the pointer, but leaving myPtr pointing at 
garbage:


handle -----> pointer ----------------------------> "Some stuff here"
myPtr -----------------------^


and as soon as you try using myPtr, you likely get the dreaded Bomb 
dialog box:

http://www.macobserver.com/tmo/article/happy-birthday-mac-how-to-recover-from-the-dreaded-bomb-box-error-message

I'm not suggesting that a 1984 memory manager is the solution to all our 
problems. I'm just pointing it out as proof that the concept works. If I 
knew more about Java and .Net, I could use them as examples instead :-)



-- 
Steven



More information about the Python-list mailing list