← All docs

memory_get_allocations()

Returns the cumulative number of successful native heap allocations, including reused blocks. Direct native reads do not allocate; eval boxes the sampled count.

memory_get_allocations()

function memory_get_allocations(): int

Returns the cumulative number of successful native heap allocations, including reused blocks. Direct native reads do not allocate; eval boxes the sampled count.

Parameters: none.

Returns: int

Availability

Compiled (AOT)Magician (eval)
AvailableAvailable
  • Hidden in strict PHP mode: this builtin is an elephc extension with no PHP equivalent, so programs compiled with --strict-php treat the name as nonexistent, in compiled code and inside eval’d code.

Examples:

$before = memory_get_allocations();
$values = array_fill(0, 10000, 1);
$after = memory_get_allocations();
echo $after - $before;

Internals

For how memory_get_allocations is implemented in the compiler, see the internals page.