Shared buffer
One can add more data to the end of the buffer, and one can remove data from the beginning of the buffer.
Additions and deletions of data are atomic, and are strictly serialized. Read accesses can occur in parallel, and can even overlap with modifications (to some degree). It is, however, ensured that reads do not see the parallel modification, i.e. reads always base on the state from the beginning of the read operation.
It is not excluded that additions can be executed in parallel. If done this way, it is guaranteed that the effects of parallel additions are the same as if they were executed in a serial way. In particular, if an addition operation returns, this addition and all parallel additions affecting preceding index positions must be done. (The current implementation does not attempt this optimization.)
Index positions are "eternal", i.e. the index position of a byte does not change when preceding bytes are deleted. Instead, a deletion merely advances the start index of the valid data (which is not necessarily 0). This model is more consistent with parallel modifications.
On 32 bit platforms it can happen that index positions wrap
around (at 1G). The position following max_int
is 0. The
length is restricted to max_int-bsize
on these platforms.
A buffer with a header of type 'h
The marshallable buffer descriptor
create pool bsize h
: Creates a buffer in pool
with a block
size of bsize
. The block size can be an arbitrary positive integer
which is always rounded up to the next multiple of the page size
of the operating system. Blocks are the units of allocation
of memory.
The valid index positions (e.g. for sub
) are start
to
start+length-1
:
Blits contents to a memory buffer
access b pos f
: Gets access to the internal string backing the
byte at position pos
. The function f
is called as f s k n
so that s.[k]
is the requested byte at pos
. The number n
is the number of valid bytes in the string.
During the execution of f
the string s
is pinned and cannot be
deleted by the garbage collector.
Adds a sub string to the end of the buffer
Adds a sub memory buffer to the end of the buffer
delete_hd b n
: Deletes n
bytes from the beginning of the buffer.
This means that the start
index is increased by n
.
Look up the buffer for this descriptor