EmbDev.net

Forum: ARM programming with GCC/GNU tools Alternative to malloc


von suresh (Guest)


Rate this post
useful
not useful
Hi all,

Iam porting a c application to arm7tdmi which contains malloc and calloc
functions.I want to know wheter is there any other method to allocate
memory other than using malloc for eg; returning a fixed memory address
using a dummy function instead of caling malloc.

Regards
Suresh

von Clifford S. (clifford)


Rate this post
useful
not useful
You can create your own version of malloc() and place that code in the
link list before the standard libraries, then your version will simply
override the standard implementation. You would also need to override
free(), even if it were just a dummy function.

I did exactly this for example when I needed to integrate zlib
decompression in a bootloader that could not use the standard library at
all. zlib called malloc exactly once with a predictable size, so I just
dummied a malloc().

All that said, why can you not simply use the standard malloc() function
(you only have to implement __sbrk or sbrk_r to make it work, examples
are provided with the WinARM tools in the syscalls.c file)

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.