Reserves enough memory to accommodate a given number of elements

public function reserve(
  int $sz,
): void;

Reserves enough memory for sz elements. If sz is less than or equal to the current capacity of this Map, this method does nothing.


  • int $sz - The pre-determined size you want for the current Map.


  • void


This example reserves space for 1000 elements and then fills the Map with 1000 integer keys and values:

const int MAP_SIZE = 1000;

function basic_usage_main(): void {
  $m = Map {};

  for ($i = 0; $i < MAP_SIZE; $i++) {
    $m[$i] = $i * 10;