Syntax:void public DsVector::allocate ($capacity)
Parameters: This function takes one parameter $Capacity,which contains the space to be allocated.Note:The capacity will remain the same if this value is less than or equal to the current capacity.Returned value:this function does not return any value.The programs below illustrate the Ds / Vector::allocate function()in PHP:Program 1: php
// Declare a new vector
$vector
=
new
DsVector ( );
echo
(
" Allocated Space is: "
);
// Using the Capacity() function
var_dump (
$vector
-> capacity());
echo
(
" Allocated space is: "
);
// Use the allocate() function for
// share power
$vector
-> allocate (50);
// Show selected vector
// capacity
var_dump (
$vector
-> capacity());
?>
Output:Allocated Space is: int (8) Allocated space is: int (50)
Program 2: php
// Declare a new vector
$vector
=
new
DsVector();
echo
(
" Allocated Space is: "
);
// Using the Capacity() function
var_dump (
$vector
-> capacity());
echo
(
" Allocated space is: "
);
// Use the allocate() function for
// share power
$vector
-> allocate (5);
// Display the capacity of the vector
var_dump (
$vector
-> capacity());
// Use the allocate() function for
// share power
$vector
-> allocate (120);
// Display the capacity of the vector
var_dump (
$vector
-> capacity());
?>
Output:Allocated Space is: int (8) Allocated space is: int (8) int (120)
Link: http://php.net/manual/en/ds-vector.allocate.php