PHP Ds\Queue allocate() Function
The Ds\Queue::allocate() Function in PHP is used to allocate memory for a Queue class instance. This function allocates sufficient memory for a given capacity for an instance of Queue class.
Syntax:
void public Ds\Queue::allocate ( int $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 be allocated.
Return Value: This method does not returns any value.
Below programs illustrate the Ds\Queue::allocate() function in PHP:
Program 1:
<?php
$pq = new \Ds\PriorityQueue();
echo ( "Allocated Space is: " );
var_dump( $pq ->capacity());
echo ( "Allocated space is: " );
$pq ->allocate(50);
var_dump( $pq ->capacity());
?>
|
Output:
Allocated Space is: int(8)
Allocated space is: int(64)
Program 2:
<?php
$q = new \Ds\Queue();
echo ( "Allocated Space is: " );
var_dump( $q ->capacity());
echo ( "Allocated space is: " );
$q ->allocate(5);
var_dump( $q ->capacity());
$q ->allocate(120);
var_dump( $q ->capacity());
?>
|
Output:
Allocated Space is: int(8)
Allocated space is: int(8)
int(128)
Reference: http://php.net/manual/en/ds-queue.allocate.php
Last Updated :
23 Aug, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...