The Ds\Map::allocate() function is an inbuilt function in PHP which is used to allocate enough memory for required capacity.
Syntax:
void public Ds\Map::allocate( $capacity )
Parameters: This function accepts single parameter $capacity which indicate number of capacity allocated.
Return Value: This function does not return any values.
Below programs illustrate the Ds\Map::allocate() function in PHP:
Program 1:
<?php // Create new map $map = new \Ds\Map(); // Use capacity() function to // display the capacity of map var_dump($map->capacity()); // Allocate capacity $map->allocate(50); // Display capacity var_dump($map->capacity()); // Allocate capacity $map->allocate(80); // Display capacity var_dump($map->capacity()); ?> |
int(8) int(64) int(128)
Program 2:
<?php // Create new map $map = new \Ds\Map(); // Declare capacity array $arr = array(10, 20, 30, 40); // Loop run for every array element foreach ($arr as $val) { // Allocate capacity $map->allocate($val); // Display capacity of map var_dump($map->capacity()); } ?> |
int(16) int(32) int(32) int(64)
Reference: https://www.php.net/manual/en/ds-map.allocate.php
Recommended Posts:
- PHP | Ds\Set allocate() Function
- PHP | Ds\Vector allocate() Function
- PHP | Ds\Sequence allocate() Function
- PHP | Ds\Deque allocate() Function
- PHP Ds\PriorityQueue allocate() Function
- PHP Ds\Queue allocate() Function
- PHP | Ds\Stack allocate() Function
- How to get the function name inside a function in PHP ?
- PHP 5 vs PHP 7
- PHP | Get PHP configuration information using phpinfo()
- PHP | php.ini File Configuration
- How to import config.php file in a PHP script ?
- PHP | imagecreatetruecolor() Function
- PHP | fpassthru( ) Function
- PHP | ImagickDraw getTextAlignment() Function
- PHP | Ds\Sequence last() Function
- PHP | Imagick floodFillPaintImage() Function
- Function to escape regex patterns before applied in PHP
- PHP | array_udiff_uassoc() Function
- PHP | geoip_continent_code_by_name() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

