3 ms·
You had my hopes up for a minute there, until I checked portability… malloc_usable_size() is a GNU extension, so usable on Linux. MacOS has malloc_size(). One
by jws 8y ago
You had my hopes up for a minute there, until I checked portability…
malloc_usable_size() is a GNU extension, so usable on Linux. MacOS has malloc_size().
One web page [1] says the GNU one is about 10 cpu cycles and the MacOS one is about 50 cpu cycles, so not the end of the world, but maybe a little long for string length checking.
I didn’t check any BSDs and I have to wonder what the effect of changing allocators in Linux has. Certainly they could have a performance impact and possible a ‘does not implement’ problem.
[1] https://lemire.me/blog/2017/09/15/how-fast-are-malloc_size-and-malloc_usable_size-in-c/ https://lemire.me/blog/2017/09/15/how-fast-are-malloc_size-a...