<div dir="ltr">Since there was no movement here I went ahead and hacked in our allocator by redefining <font face="monospace, monospace">malloc</font>, <font face="monospace, monospace">calloc</font>, <font face="monospace, monospace">realloc</font>, and <font face="monospace, monospace">free</font> to point to <font face="monospace, monospace">extern'</font>d functions that I define in our application. This yielded some performance benefits for us, so I'm hoping that a more standard HarfBuzz solution might appear at some point :)<div><br></div><div>If you're not keen on the idea of allowing the allocator to be swapped out at runtime, would you at least allow it to be <font face="monospace, monospace">extern</font>'d at compile time? I'm not familiar with HarfBuzz coding standards, but I'd propose adding something like a <font face="monospace, monospace">HAVE_EXTERNAL_ALLOCATOR</font> define to control this, and then define your own allocator functions that you'd use in place of <font face="monospace, monospace">malloc</font>, etc.</div><div><br></div><div>Basically, something like this (I currently have this code in <font face="monospace, monospace">hb-private.hh</font>):</div><div><br></div><div><div><font face="monospace, monospace">/* Define our allocation functions. These may be provided by an </font></div><div><font face="monospace, monospace"> * external source when HAVE_EXTERNAL_ALLOCATOR is defined. */</font></div><div><font face="monospace, monospace">#ifdef HAVE_EXTERNAL_ALLOCATOR</font></div><div><font face="monospace, monospace">extern void* _hb_malloc(size_t);</font></div><div><font face="monospace, monospace">extern void* _hb_calloc(size_t, size_t);</font></div><div><font face="monospace, monospace">extern void* _hb_realloc(void*, size_t);</font></div><div><font face="monospace, monospace">extern void _hb_free(void*);</font></div><div><font face="monospace, monospace">#define hb_malloc _hb_malloc</font></div><div><font face="monospace, monospace">#define hb_calloc _hb_calloc</font></div><div><font face="monospace, monospace">#define hb_realloc _hb_realloc</font></div><div><font face="monospace, monospace">#define hb_free _hb_free</font></div><div><font face="monospace, monospace">#else</font></div><div><font face="monospace, monospace">#define hb_malloc malloc</font></div><div><font face="monospace, monospace">#define hb_calloc calloc</font></div><div><font face="monospace, monospace">#define hb_realloc realloc</font></div><div><font face="monospace, monospace">#define hb_free free</font></div><div><font face="monospace, monospace">#endif</font></div></div><div><br></div><div>You'd then replace calls to <font face="monospace, monospace">malloc</font>, <font face="monospace, monospace">calloc</font>, <font face="monospace, monospace">realloc</font>, and <font face="monospace, monospace">free</font><font face="arial, helvetica, sans-serif"> from within HarfBuzz to use </font><font face="monospace, monospace">hb_malloc</font>, <font face="monospace, monospace">hb_calloc</font>, <font face="monospace, monospace">hb_realloc</font>, and <font face="monospace, monospace">hb_</font><span style="font-family:monospace,monospace">free</span><font face="arial, helvetica, sans-serif">.</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">This is basically the code I already have, except I redefined </font><font face="monospace, monospace">malloc</font>, <font face="monospace, monospace">calloc</font>, <font face="monospace, monospace">realloc</font>, and <font face="monospace, monospace">free</font><font face="arial, helvetica, sans-serif"> rather than create the </font><font face="monospace, monospace">hb_*</font><font face="arial, helvetica, sans-serif"> variants, as I didn't want to change too much HarfBuzz code.</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">Thoughts?</font></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 31 August 2015 at 22:17, Jamie Dale <span dir="ltr"><<a href="mailto:jamiedale88+harfbuzz@gmail.com" target="_blank">jamiedale88+harfbuzz@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hey,<br><br>I'm not sure if this is correct place to post/discuss feature requests... hopefully it is.<br><br>Our project makes use of a custom memory allocator, and we like to ensure that our third-party libraries are using this where possible, as our allocator can offer significantly better performance, and can also allow us better memory profiling and debugging support.<br><br>A look through the HarfBuzz source code would suggest that it doesn't currently support custom memory allocators, and instead just directly calls the standard malloc/free/etc functions. I was wondering if you'd ever considered (or would consider) adding a way to override this behaviour?<br><br>In my case, I'd just need a single global override to be set before my first call to any other HarfBuzz code... basically something like the FT_Memory struct from FreeType:<br><a href="http://www.freetype.org/freetype2/docs/reference/ft2-system_interface.html#FT_Memory" target="_blank">http://www.freetype.org/freetype2/docs/reference/ft2-system_interface.html#FT_Memory</a><br><br>Thanks,<br>Jamie.</div>
</blockquote></div><br></div>