Memory management in Perl XS
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
- Equivalent to
malloc
. Newxc
- Equivalent to
malloc
with a cast, for C++. Newxz
- Equivalent to
calloc
.
The following is a legacy interface:
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
.
Web links
Copyright © Ben Bullock 2009-2024. All
rights reserved.
For comments, questions, and corrections, please email
Ben Bullock
(benkasminbullock@gmail.com).
/
Privacy /
Disclaimer