• PHP Video Tutorials

PHP - Ds Vector allocate() Function



Ds\Vector::allocate() function can allocate enough memory for the required capacity.

Syntax

public void Ds\Vector::allocate( int $capacity )

Ds\Vector::allocate() function can make sure that enough memory is allocated for the required capacity. It can remove the need to reallocate an internal as values are added.

Ds\Vector::allocate() function doesn't return any value.

Example 1

<?php 
   $vector = new \Ds\Vector(); 
  
   echo("Allocated memory:"); 
   var_dump($vector->capacity()); 
  
   echo("Allocated memory:"); 
   $vector->allocate(50); 
  
   var_dump($vector->capacity()); 
?> 

Example 2

<?php 
   $vector = new \Ds\Vector(); 
  
   echo("Allocated momory:"); 
   var_dump($vector->capacity()); 
  
   echo("Allocated memory:"); 
   $vector->allocate(7); 

   var_dump($vector->capacity()); 
   $vector->allocate(100); 
  
   var_dump($vector->capacity()); 
?> 
php_function_reference.htm
Advertisements