Add memory function callbacks.

This allows the user of the library to provide own memory functions.
Very useful if the user uses a VM with own memory management or
environments with of implementations of malloc/realloc/free.