lua-users home
lua-l archive

Re: Using Lua in an embedded hardware environment (toward a porting guide)

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Fabien wrote:
> Having some statistical informations about typical memory usage would be
> great as well: is it worth implementing special tricks to speed up
> allocation and/or limit fragmentation on the sometimes naive memory
> allocators one gets on embedded platforms? Are there some known ways to
> do this? 
Alas, I cannot help with the stats. I struggled with writing my own
malloc()/realloc() when I was attaching Lua to some boot code. I had
512K to work with (program + data), so LOTS of room by the standards of
other embedded systems. I decided that a better use of my time was to
download Doug Lea's malloc():
 http://g.oswego.edu/dl/html/malloc.htm
It was little confusing at first, trying to figure out the best way to
get it integrated, but by making the sbrk/MORECORE backend return the
rest of memory on the very first call. On the next call (which doesn't
happen except when I intentionally use up all memory), it will emit a
message and fail - as in reset!
I found that the dlmalloc() allocator met my needs - but I wasn't
pushing it for performance. I suspect that tweaking it for fragmentation
will not be necessary.
Doug (not Lea)

AltStyle によって変換されたページ (->オリジナル) /