Added support for custom memory alloc/free functions