write pmalloc function