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 own implementations of malloc/realloc/free.