I have a stack of objects that changes size.  It never gets very large, but 
it varies in size a lot.  Much of my program's time is spent creating 
objects to push onto the stack and then GCing them when they are popped.

This seems like an "obvious" place to do some kind of manual pooling of 
instances.  Has anyone tried this?

The simplest approach would be to allocate an array of these things, and 
then mutate the existing instances instead of actually adding/deleting 
instances.  The array would need to grow a few times as the stack 
increases, but would reach some limit and then be stable.

Currently the objects are Julia "immutable" types.  Presumably there's an 
advantage to have them all in contiguous memory (inside the array/stack).  
But then I cannot mutate them. 

 If I make them "type" instances then I don't see how I get them in 
contiguous memory.  Particularly during re-allocation when the array grows.

So...

Does the above approach to memory pooling make sense?  Has anyone done 
something similar?  Does the worry about memory locality make sense?  Is 
there a solution?

Thanks,
Andrew

Reply via email to