This is automatic generated document for things in Swow\Buffer class
Class Buffer
Constants
This constant holds page size of this machine, it’s platform-dependent.
At Linux mips64 and macOS arm64 platforms, this constant may have a value 16384
Methods
Static method alignSize
Round the size up to a multiple of the alignment.
The alignment must be a power of two. Other values give a result that is not a multiple.
Returns int the aligned size
Method __construct
Create a buffer and allocate the memory.
Use new Buffer(0) when the size is not known. Then call alloc().
Method __debugInfo
Returns array<string, mixed> debug information for var_dump
Method __serialize
Serialize the value.
The size is not kept. After unserialize() the size equals the length.
Method __toString
Method __unserialize
Method alloc
Allocate the memory.
The method works only on a buffer without memory. Use new Buffer(0).
Throws \Error when the buffer already has memory
Method append
append $string to the end of buffer
$start and $length is for input $string The buffer grows when the data does not fit.
Returns int bytes written
Throws \ValueError when specified $start, $offset or $length not in range
Method clear
Method close
Free the memory and set size and length to 0.
A second close() does nothing. A write after close() returns the byte count and discards the data.
Method dupString
Method extend
Grow the buffer.
The buffer doubles its size until it reaches the recommended size. The result can be larger than the request.
Param int $recommendSize [optional] = $this->getSize() * 2
Throws \ValueError when the size is not larger than the current size
Method fetchString
Get the value and reset the buffer.
Returns string the value
Throws \Error when the buffer is locked
Method getAvailableSize
Method getLength
Method getLocker
Returns (Coroutine | null) the locker, or null
Method getSize
Method isAvailable
Method isEmpty
Method isFull
Method isLocked
Returns bool true when the buffer is locked
Method lock
Lock the buffer.
A locked buffer rejects write operations with Error. The lock holder is not exempt. The lock stops write calls only. It is not a mutex.
Throws \Error when the buffer is already locked
Method mallocTrim
Free the unused memory.
The buffer shrinks to the used length.
Method prepare
Method read
read at max $length bytes data from start
Returns string data read
Throws \ValueError when specified $start and $length not in range
Method realloc
Method toString
Method truncate
Returns int length of buffer after truncate
Method truncateFrom
Param int $offset [optional] = $this->getOffset()
Returns int length of buffer after truncate
Method tryLock
Try to lock the buffer.
Returns bool false when the buffer is locked
Method unlock
Unlock the buffer.
Throws \Error when the buffer is not locked, or when the caller is not the locker
Method write
write $string to buffer
$start and $length is for input $string $offset is for output $buffer
The offset must not be larger than the current length. The first write into a new buffer starts at 0. The buffer grows when the data does not fit.
Returns int bytes written
Throws \ValueError when specified $start, $offset or $length not in range