add memory allocation function