make memory allocation a callback inside memory layer