ufairiya / mongoose

Automatically exported from code.google.com/p/mongoose
MIT License
0 stars 0 forks source link

Adding the capability of using custom memory allocation routines #215

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I have created a clone to add in support for using a custom memory allocation 
setup.  This is such that I can use it in my project (havokmud, which lives on 
github) and use my own memory allocation scheme which saves me a very large 
amount of memory.

The changes to mongoose are fairly small.  I have created a struct that has 
pointers to all of the various memory allocation routines (calloc, malloc, 
free, realloc), and added a function to initialize a pointer to a global copy 
of these to the API.  Additionally, all internal uses have been switched to use 
mg_malloc, mg_calloc, mg_free, mg_realloc, and these four routines have been 
created.  If the allocator structure has not been registered, or a particular 
function within the structure has not been registered, the standard libc ones 
will be used.

https://code.google.com/r/gjhurlbu-custom-memory-mongoose/

Original issue reported on code.google.com by gjhur...@gmail.com on 27 Dec 2010 at 7:31

GoogleCodeExporter commented 9 years ago
I believe you can get away without any code modification at all. Compile 
mongoose.c with -Dmalloc=my_alloc , and link against your file where you have 
those implemented.

Original comment by valenok on 21 Jun 2011 at 11:31

GoogleCodeExporter commented 9 years ago
So instead of supporting it nicely in the code, you would want me to use 4 
overrides from the command line?  I guess I'll be maintaining a fork for a 
while then.

This change isn't just for overriding malloc.  It overrides malloc, calloc, 
realloc and free, all of which are used in mongoose.  Additionally, doing it 
the way you have indicated may not work correctly with valgrind or other 
redirectors that are used to check memory use.

In short: adding -Dmalloc=my_alloc -Dcalloc=my_calloc -Drealloc=my_realloc 
-Dfree=my_free is not palatable.  Thanks anyways.

Original comment by gjhur...@gmail.com on 21 Jun 2011 at 11:42