PHP | Ds\Stack allocate() Function
The Ds\Stack::allocate() function is an inbuilt function in PHP which is used to allocate memory for required capacity. This function allocates sufficient memory for a given capacity of an instance of Stack class.
Syntax:
void Ds\Stack::allocate( $capacity )
Parameters: This function accepts a single parameter $capacity which is an integral value denoting the number of values for which capacity is needed to allocate.
Return Value: This function does not return any value.
Below programs illustrate the Ds\Stack::allocate() function in PHP:
Program 1:
<?php // PHP program to illustarte the // Ds\Stack::allocate() function // Create a Stack instance $stack = new \Ds\Stack(); echo("Allocated Space is: "); // Use capacity() function var_dump($stack->capacity()); echo("Allocated space is: "); // Use allocate() function to // allocate capacity $stack->allocate(50); // Display the allocated stack // capacity var_dump($stack->capacity()); ?> |
Allocated Space is: int(8) Allocated space is: int(50)
Program 2:
<?php // Declare new stack $stack = new \Ds\Stack(); echo("Allocated Space is: "); // Use capacity() function var_dump($stack->capacity()); echo("Allocated space is: "); // Use allocate() function to // allocate capacity $stack->allocate(5); // Display the stack capacity var_dump($stack->capacity()); echo("Allocated space is: "); // Use allocate() function to // allocate capacity $stack->allocate(120); // Display the stack capacity var_dump($stack->capacity()); ?> |
Allocated Space is: int(8) Allocated space is: int(8) Allocated space is: int(120)
Reference: https://www.php.net/manual/en/ds-stack.allocate.php
Recommended Posts:
- PHP | Ds\Set allocate() Function
- PHP | Ds\Map allocate() Function
- PHP Ds\Queue allocate() Function
- PHP Ds\PriorityQueue allocate() Function
- PHP | Ds\Deque allocate() Function
- PHP | Ds\Sequence allocate() Function
- PHP | Ds\Vector allocate() Function
- How to call a function that return another function in JavaScript ?
- How to get the function name inside a function in PHP ?
- How to get the function name from within that function using JavaScript ?
- p5.js | second() function
- PHP | end() Function
- p5.js | pow() function
- PHP | pi( ) Function
- p5.js | max() 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.



