seperated allocate method for allocating raw and typed memory