Module ext_php_rs::boxed
source · Expand description
A pointer type for heap allocation using the Zend memory manager.
Heap memory in PHP is usually request-bound and allocated inside memory
arenas, which are cleared at the start and end of a PHP request. Allocating
and freeing memory that is allocated on the Zend heap is done through two
separate functions efree
and emalloc
.
As such, most heap-allocated PHP types cannot be allocated on the stack,
such as ZendStr
, which is a dynamically-sized type, and therefore must
be allocated on the heap. A regular Box
would not work in this case, as
the memory needs to be freed from a separate function zend_string_release
.
The ZBox
type provides a wrapper which calls the relevant release
functions based on the type and what is inside the implementation of
ZBoxable
.
This type is not created directly, but rather through a function implemented
on the downstream type. For example, ZendStr
has a function new
which
returns a ZBox<ZendStr>
.
Structs§
- A pointer type for heap allocation using the Zend memory manager.