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:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php 
  
// Declare new PriorityQueue 
$pq = new \Ds\PriorityQueue(); 
  
echo("Allocated Space is: "); 
  
// Use capacity() function 
var_dump($pq->capacity()); 
  
echo("Allocated space is: "); 
  
// Use allocate() function to 
// allocate capacity 
$pq->allocate(50); 
  
// Display the allocated vector 
// capacity 
var_dump($pq->capacity()); 
  
?> 

chevron_right


Output:

Allocated Space is: int(8)
Allocated space is: int(64)

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php 
   
// Declare new Queue 
$q = new \Ds\Queue(); 
   
echo("Allocated Space is: "); 
   
// Use capacity() function 
var_dump($q->capacity()); 
   
echo("Allocated space is: "); 
   
// Use allocate() function to 
// allocate capacity 
$q->allocate(5); 
   
// Display the allocated vector 
// capacity 
var_dump($q->capacity()); 
   
// Use allocate() function to 
// allocate capacity 
$q->allocate(120); 
   
// Display the allocated vector 
// capacity 
var_dump($q->capacity()); 
   
?> 

chevron_right


Output:

Allocated Space is: int(8)
Allocated space is: int(8)
int(128)

Reference: http://php.net/manual/en/ds-queue.allocate.php



My Personal Notes arrow_drop_up

The function of education is to teach one to think intensively and to think critically

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.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.