[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Question about Lua 5.1.3 and realloc() on life.lua
- From: "Bogdan Marinescu" <bogdan.marinescu@...>
- Date: Fri, 2 May 2008 16:44:29 +0300
My allocator does best fit too, and coalescing on malloc/free/realloc,
probably we implemented something quite similar. It also has two
areas, a 'fixed' area with small blocks (16 or 32 bytes) and a dynamic
area that can accommodate blocks of different sizes. I'm not a
specialist by any measure when it comes to allocators, but at this
point experience (with this project and previous projects) dictates
that a low-fragmentation allocator needs some sort of 'bins'
implementation (even though this is only an educated guess, as I'm
still trying to get some 'real' statistics from Newlib's dlmalloc
implementation). Windows uses something similar with its heaps (I
think I saw a related thread recently on this list). I find tuning a
real problem when you're limited to just 64k of RAM and you want to be
able to execute as much as possible from there.
On Fri, May 2, 2008 at 4:30 PM, Ralph Hempel
<rhempel@hempeldesigngroup.com> wrote:
> Bogdan Marinescu wrote:
>
>
> > Fortunately,
> > dlmalloc is what Newlib uses, so at least ARM platforms are OK, since
> > all the ARM embedded toolchains I know use Newlib. And yes,
> > percentages are good :)
> >
>
> I've written a stripped down best-fit malloc that is very fast on
> ARM7 devices with very limited RAM. I still get fragmentation on
> the order of 20-30%.
>
> The typical use of pbLua on LEGO MINDSTORMS NXT is in console mode, so
> there's a lot of messing around with relatively short strings.
>
> I did review dlmalloc() but decided (perhaps foolishly) that it
> was too much code for what I was doing. No doubt it works in
> a lot of different environments, but all those switches ended up
> intimidating me.
>
> The binning of chunks is a great idea when you need to find a free
> block. My allocator does free block coalescing whenever possible
> but I should really look at using up older chunks first, like dlmalloc
> does.
>
> Sorry for the rambling post, but it's clear that deciding which
> malloc to use has a lot of tradeoffs. Having written my own
> allocator and spent more time testing and debugging than I ever thought
> possible, I can highly recommend picking one that you know works. :-)
>
> Worry about tuning if it's a real problem.
>
> Ralph
>