vnmakarov / mir

A lightweight JIT compiler based on MIR (Medium Internal Representation) and C11 JIT compiler and interpreter based on MIR
MIT License
2.29k stars 145 forks source link

Supplying custom allocation/deallocation routines #372

Open ningvin opened 11 months ago

ningvin commented 11 months ago

I am usually working in an environment where custom allocators are used for various reasons and usage of plain malloc/free is frowned upon. Thankfully many libraries allow their users to supply custom (de)allocation routines.

While support for this can be as simple as some defines that default to malloc/free, I always found that in practice it is way more convenient to be able to pass some user data (often just a void*) to the (de)allocation routines (similar to what is suggested in #356). See for example PCRE2 that does this upon context creation (e.g. pcre2_general_context_create).

If you feel that this would fit MIR and is worth pursuing, I could try to put together a pull request for this :-)

vnmakarov commented 11 months ago

Sorry for long delay with the answer, I overlooked your message. I think custom allocation would be useful for some applications. So it is worth to pursue this. I only have one important requirement is to save somehow the old library interface for compatibility.

ningvin commented 10 months ago

Thanks for your feedback :-) I am currently a bit busy with some other stuff, so it might be a while until I have something to show. Just to clarify: by library interface you mean the functions/types in mir.h and mir-gen.h and the like, but not e.g. mir-htab.h and mir-varr.h, correct?