PHP Ds\Dequealloc()函数用法示例

2021年4月7日18:57:47 发表评论 801 次浏览

PHP Ds\Deque::allocate()函数是PHP中的内置函数, 用于根据参数指定分配内存。如果未定义参数, 则将创建默认大小的双端队列。

PHP的双端队列分配内存函数使用语法如下:

public Ds\Deque::allocate( $capacity ) : void

参数:该函数接受单个参数$容量其中包含要为其分配空间的值的数量。

PHP Dequealloc返回值:此函数不返回任何值。

下面的程序说明了PHP中的Ds\Deque::allocate()函数:

PHP双端队列分配内存程序1:

<?php
  
//Declare Deque of default size
$deq = new \Ds\Deque();
  
//Display the capacity of Deque
var_dump( $deq ->capacity());
  
  
//Allocating space for 50 values
//to the Deque
$deq ->allocate(50);
  
//Display the capacity of Deque
var_dump( $deq ->capacity());
  
?>

输出如下:

int(8)
int(64)

PHP Dequealloc程序2:

<?php
   
//Declare Deque of default size
$deck = new \Ds\Deque();
  
//Display the Deque capacity
var_dump( $deck ->capacity());
   
//Allocating space for 50 values
//to the Deque
$deck ->allocate(50);
  
//Display the Deque capacity
var_dump( $deck ->capacity());
   
//Allocating space for 60 values
//to the Deque
$deck ->allocate(60);
  
//Display the Deque capacity
var_dump( $deck ->capacity());
   
?>

输出如下:

int(8)
int(64)
int(64)

参考: http://php.net/manual/en/ds-deque.allocate.php


木子山

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: