Rewrite memory functions.

This allows us to control both the data buffer and the buffer struct.