• PHP Video Tutorials

PHP - Ds Sequence allocate() Function


Advertisements

Ds\Sequence::allocate() function can allocate enough memory for a required capacity.

Syntax

public abstract void Ds\Sequence::allocate( int $capacity )

Ds\Sequence::allocate() function can ensure that enough memory is allocated for the required capacity. It removes the need to reallocate the internal as values are added.

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

Example 1

<?php 
   $seq = new \Ds\Vector(); 
   var_dump($seq->capacity()); 
  
   $seq->allocate(20);
   var_dump($seq->capacity());
  
   $seq->allocate(100); 
   var_dump($seq->capacity()); 
?>

Example 2

<?php 
   $seq = new \Ds\Vector();
   $arr = array(10, 20, 30, 40, 50);
  
   foreach($arr as $val) { 
      $seq->allocate($val); 
      var_dump($seq->capacity());
   }
?>
php_function_reference.htm
Advertisements