This is automatic generated document for things in Swow\SharedBuffer class

Class SharedBuffer

A shared memory byte buffer with named and anonymous mappings.

An anonymous buffer is visible to threads of this process and to a forked child. A named buffer is visible to another process that attaches the same name. The buffer does not lock. The caller coordinates access. The typed methods use offsetBytes as a byte offset and count as an element count. The endian argument selects the byte order.

Constants

public BIG_ENDIAN = 2

Store and load typed values in big-endian order.

public LITTLE_ENDIAN = 1

Store and load typed values in little-endian order.

public NATIVE_ENDIAN = 0

Use the byte order of this machine.

Methods

Static method attachNamed

public static function attachNamed ( string $name ) : self

Attach a named buffer.

Static method createNamed

public static function createNamed ( string $name , int $size , int $alignment , int $flags ) : self

Create a named buffer.

Param string $name mapping name Param int $size size in bytes Param int $alignment alignment in bytes, a power of two from 8 to 4096 Param int $flags bit 0 removes the name when the last handle releases the buffer

Throws \ValueError when the alignment is not valid Throws \Swow\SyncException when the name exists or the buffer cannot be created

public static function unlink ( string $name ) : void

Remove a name. An existing mapping stays valid.

Method __construct

public function __construct ( int $size , int $alignment )

Create an anonymous buffer.

Param int $size size in bytes Param int $alignment alignment in bytes, a power of two from 8 to 4096

Throws \ValueError when the size is not positive or the alignment is not valid Throws \Swow\SyncException when the buffer cannot be created

Method __debugInfo

public function __debugInfo ( ) : array

Return debug information.

Method __serialize

public function __serialize ( ) : array

Serialize the buffer by name or shared object id.

Method __unserialize

public function __unserialize ( array $data ) : void

Restore the buffer from a name or shared object id.

Method clear

public function clear ( ) : void

Set all bytes to zero.

Method copyFrom

public function copyFrom ( self $source , int $sourceOffsetBytes , int $destinationOffsetBytes , int $lengthBytes ) : void

Copy bytes between buffers.

Method fill

public function fill ( int $offsetBytes , int $lengthBytes , int $byte ) : void

Fill bytes with one value.

Method getAlignment

public function getAlignment ( ) : int

Return the alignment in bytes.

Method getName

public function getName ( ) : ?string

Return the name, or null for an anonymous buffer.

Method getRefCount

public function getRefCount ( ) : int

Return the reference count of the mapping.

The threads and the forked children that map the same buffer share the count, so it is not the number of handles in this process.

Method getSharedId

public function getSharedId ( ) : int

Return the shared object id.

Method getSize

public function getSize ( ) : int

Return the buffer size in bytes.

Method read

public function read ( int $offsetBytes , int $lengthBytes ) : string

Copy bytes out of the buffer.

Method slice

public function slice ( int $offset , int $size ) : self

Return a view of a byte range of this buffer.

The view holds a reference to this buffer, and it cannot be serialized.

Param int $offset offset in bytes Param int $size size in bytes

Throws \ValueError when the range is outside the buffer Throws \Swow\SyncException when the view cannot be created

Method viewF32

public function viewF32 ( int $offsetBytes , int $count , int $endian ) : array

Load 32-bit float values at a byte offset.

Method viewF64

public function viewF64 ( int $offsetBytes , int $count , int $endian ) : array

Load 64-bit float values at a byte offset.

Method viewI16

public function viewI16 ( int $offsetBytes , int $count , int $endian ) : array

Load signed 16-bit integers at a byte offset.

Method viewI32

public function viewI32 ( int $offsetBytes , int $count , int $endian ) : array

Load signed 32-bit integers at a byte offset.

Method viewI64

public function viewI64 ( int $offsetBytes , int $count , int $endian ) : array

Load signed 64-bit integers at a byte offset.

Method viewI8

public function viewI8 ( int $offsetBytes , int $count , int $endian ) : array

Load signed 8-bit integers at a byte offset.

Method viewU16

public function viewU16 ( int $offsetBytes , int $count , int $endian ) : array

Load unsigned 16-bit integers at a byte offset.

Method viewU32

public function viewU32 ( int $offsetBytes , int $count , int $endian ) : array

Load unsigned 32-bit integers at a byte offset.

Method viewU64

public function viewU64 ( int $offsetBytes , int $count , int $endian ) : array

Load unsigned 64-bit integers at a byte offset.

Method viewU8

public function viewU8 ( int $offsetBytes , int $count , int $endian ) : array

Load unsigned 8-bit integers at a byte offset.

Method write

public function write ( int $offsetBytes , string $data ) : void

Copy bytes into the buffer.

Method writeF32

public function writeF32 ( int $offsetBytes , array $values , int $endian ) : void

Store 32-bit float values at a byte offset.

Method writeF64

public function writeF64 ( int $offsetBytes , array $values , int $endian ) : void

Store 64-bit float values at a byte offset.

Method writeI16

public function writeI16 ( int $offsetBytes , array $values , int $endian ) : void

Store signed 16-bit integers at a byte offset.

Method writeI32

public function writeI32 ( int $offsetBytes , array $values , int $endian ) : void

Store signed 32-bit integers at a byte offset.

Method writeI64

public function writeI64 ( int $offsetBytes , array $values , int $endian ) : void

Store signed 64-bit integers at a byte offset.

Method writeI8

public function writeI8 ( int $offsetBytes , array $values , int $endian ) : void

Store signed 8-bit integers at a byte offset.

Method writeU16

public function writeU16 ( int $offsetBytes , array $values , int $endian ) : void

Store unsigned 16-bit integers at a byte offset.

Method writeU32

public function writeU32 ( int $offsetBytes , array $values , int $endian ) : void

Store unsigned 32-bit integers at a byte offset.

Method writeU64

public function writeU64 ( int $offsetBytes , array $values , int $endian ) : void

Store unsigned 64-bit integers at a byte offset.

Method writeU8

public function writeU8 ( int $offsetBytes , array $values , int $endian ) : void

Store unsigned 8-bit integers at a byte offset.


Copyright 2022 the Swow contributors

This site uses Just the Docs, a documentation theme for Jekyll.