Refactored the allocation to separate out the memory and accounting information allocation
Share the same code between alloc and realloc