Ds \ PriorityQueue :: allocate()PHP中的函数用于为PriorityQueue类实例分配内存。该函数为给定的PriorityQueue类实例的容量分配足够的内存。
语法如下:
void public Ds\PriorityQueue::allocate ( int $capacity )
参数:该函数接受单个参数$容量这是一个整数值, 表示需要为其分配容量的值的数量。
返回值:此方法不返回任何值。
下面的程序说明了Ds \ PriorityQueue :: allocate()PHP中的功能:
程序1:
<?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());
?>
输出如下:
Allocated Space is: int(8)
Allocated space is: int(64)
程式2:
<?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(5);
// Display the allocated vector
// capacity
var_dump( $pq ->capacity());
// Use allocate() function to
// allocate capacity
$pq ->allocate(120);
// Display the allocated vector
// capacity
var_dump( $pq ->capacity());
?>
输出如下:
Allocated Space is: int(8)
Allocated space is: int(8)
int(128)
参考:http://php.net/manual/en/ds-priorityqueue.allocate.php