soasis / cuneicode

A C library for converting between two different encodings in a simple, easy, and powerful way.
http://ztdcuneicode.rtfd.io/
Other
55 stars 7 forks source link

Quick question: is it possible to override the allocator to use something like mimalloc and jemalloc? #5

Open Trung0246 opened 1 year ago

Trung0246 commented 1 year ago

As title said. However I'm not even sure if it possible yet. Unless I missed something in the documentation.

ThePhD commented 1 year ago

The way to change how allocation is done internally in the library is to provide your own heap. The heap portion is not fully documented, but it's part of the function signature: https://ztdcuneicode.readthedocs.io/en/latest/api/heap.html

This will cause the entire API in cuneicode to use specifically that heap. You can fill in the functions from mimalloc and jemalloc to do this by making those functions and create the heap structure, then passing it into the cnc_registry_open function: https://ztdcuneicode.readthedocs.io/en/latest/api/registry.html#_CPPv417cnc_registry_openPP23cnc_conversion_registryP19cnc_conversion_heap20cnc_registry_options

If you notice any allocations not going through the heap, do let me know. In general, the entire API was designed to NOT allocate whatsoever, so if it starts allocating that means there's a problem somewhere.

ThePhD commented 1 year ago

If you mean "how do I stop allocation for the regular functions that aren't related to the registry", the answer is "they never allocate, ever, so it's a moot question".

Some of the convenience functions might allocate, but in that case I'd make them take a heap. The convenience functions are not here yet, however, because they require statement expressions and using those in a high-warning-level environment like I do is such a pain that I have not gotten them off the ground yet.