To allocate memory in XS, use
void Newx(void* ptr, int nitems, type); void Newxc(void* ptr, int nitems, type, cast); void Newxz(void* ptr, int nitems, type);
Newx
malloc.
Newxc
malloc with a cast, for C++.
Newxz
calloc.
void New(int id, void* ptr, int nitems, type ); void Newz(int id, void* ptr, int nitems, type ); void Newc(int id, void* ptr, int nitems, type , cast );This is mentioned in the book "Extending and Embedding Perl" by Simon Cozens. It became obsolete in Perl 5.9.3.
There is also an interface to realloc
You can free the memory with something called Safefree.