开发者

Custom Allocator for a Toy Language

I have a toy language to compiles into C++ which runs on a MCU with 2 kb of ram (I do not have access to std c++ lib or boost etc.), in order to keep things uniform all my objects are allocated in heap. The problem is avr-gcc,

http://www.nongnu.org/avr-libc/user-manual/malloc.html

uses two byte header for each malloced object, AFAIK t开发者_StackOverflow中文版hat means a function object returned that has no state consumes 3 bytes (1 byte to conform to the standart + 2 byte malloc info), for ints it consumes 4 bytes (2 byte info + 2 byte for int itself) pretty much doubling all my object sizes, so a simple turn led on/off application consumes 1k of ram.

I already have my own object system which overrides new/delete (avr-gcc does not have it implemented.) so I am thinking may be custom allocator will consume less memory and speed things up a bit since it will serve request from a chunk that is already allocated. Are there any implementations that would work in my case?


Just don't allocate/return many small objects. I'd create array for my objects and pass indices as arguments and return value.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜