avr-gcc-list
[Top][All Lists]
Advanced

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

[avr-gcc-list] Minimal malloc implementation


From: Tom Harris
Subject: [avr-gcc-list] Minimal malloc implementation
Date: Wed, 4 Jun 2003 12:25:52 +1000

Greetings,

I have a minimal malloc that may be useful to others. The behaviour is as
the standard malloc(), except that allocated memory is never tracked, so
once malloc'ed, its yours for good. The free() function is a no-op. This is
useful for the class of embedded apps that allocate memory at startup and
never thereafter. The stdio functions use malloc for a buffer, that is never
free'ed, so by using the minimal malloc you can save about 500 bytes, which
may be important.

If this file is compiled, and the resulting object file linked into your
project, it should prevent the linking of the standard malloc from libc.
This works for me, anyway. I would have preferred to have the free()
implementation generate an error, as if you are calling free() from your
code, you can expect to run out of memory, but I do not see a way of doing
this easily. I just check the output of avr-objdump for the final object
file for the project to check that no free() calls have crept in.

This code is alpha, I have not tested it much. Perhaps it should be in the
standard library as an alernative implementation, in the spirit of the 3
vfprintf() implementations. 

TomH <tomh(AT)optiscan(DOT)com>

Attachment: pwmalloc.c
Description: Binary data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]