1
0
mirror of https://github.com/elua/elua.git synced 2025-01-08 20:56:17 +08:00
elua/inc/salloc.h
Bogdan Marinescu 59c35cc20d Added a very simple allocator to eLua. It's probably the most basic version of a chained blocks allocator. It's slow and it won't handle fragmentation nearly as well as dlmalloc(), but it's much smaller and it doesn't need the extra book-keeping space needed by dlmalloc (about 1KB for each memory space).
Recommended only for systems with very low memory (Flash/RAM), and prefferably systems running only precompiled Lua (if you need to compile the code, you might get into stack overflows, and this allocator is much more sensitive to this kind of stuff than dlmalloc()). In fact, this allocator seems to suggest that one should set the stack to at least 4k for the Lua parser to run properly even on small programs. I won't do this just yet, rather I'll keep on trying to move the Lua parser data structures from stack to heap. For now we're OK with the current configuration.
The allocator can handle multiple memory spaces.
Enable with "allocator=simple" on the scons command line.

...oh yes, also added a newline to the end of elua_adc.c :) (to avoid some annoying warnings)
2009-02-18 22:13:48 +00:00

15 lines
308 B
C

// A very simple, quite inneficient, yet very small memory allocator
#ifndef __SALLOC_H__
#define __SALLOC_H__
#include <stddef.h>
void* smalloc( size_t size );
void sfree( void* ptr );
void* scalloc( size_t nmemb, size_t size );
void* srealloc( void* ptr, size_t size );
#endif // #ifndef __SALLOC_H__