Re: wxEuphoria on FreeBSD

new topic     » goto parent     » topic index » view thread      » older message » newer message

Matt Lewis wrote:
> I haven't even really attempted to figure out what you do with all the
> cache and pool junk in there.

Originally (many years ago, pre-1.0) I just made direct calls 
to malloc() and free(), but profiling showed that malloc()/free() 
was consuming a fair bit of time, so I added the "storage cache" idea.

I created about 14(?) linked lists of standardized block sizes, up to
a certain large (and uncommon) size. "free" just links a block onto 
the appropriate-sized list, while "allocate" normally just grabs 
the first item on the list. These operations are very fast, 
just a few machine instructions. This is also efficient for
accesses to the CPU data cache, since the most recently freed block
is the first to be reused. I found there are often loops where the 
same sized blocks are allocated and freed over and over. 

This speeds things up, and quite often eliminates virtually all 
calls to malloc/free inside a loop. However, I don't think this 
is a huge win, as implementations of malloc have improved over 
the years, and in fact they sometimes implement something very 
similar to what I did. Also, there is an issue of having a whole
bunch of freed blocks of a certain size when the demand shifts
to blocks of a different size. A mechanism is in place to 
deal with this.

Regards,
   Rob Craig
   Rapid Deployment Software
   http://www.RapidEuphoria.com

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu