module Netmcore_buffer:Shared buffersig
..end
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.
type 'a
buffer
'h
type 'a
buffer_descr
val create : Netmcore.res_id -> int -> 'a -> 'a buffer
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.val destroy : 'a buffer -> unit
sub
) are start
to
start+length-1
:val start : 'a buffer -> int
val length : 'a buffer -> int
val contents : 'a buffer -> string
val sub : 'a buffer -> int -> int -> string
val blit_to_string : 'a buffer -> int -> string -> int -> int -> unit
val blit_to_memory : 'a buffer -> int -> Netsys_mem.memory -> int -> int -> unit
val access : 'a buffer -> int -> (string -> int -> int -> 'b) -> 'b
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.
val add_string : 'a buffer -> string -> unit
val add_sub_string : 'a buffer -> string -> int -> int -> unit
val add_sub_memory : 'a buffer -> Netsys_mem.memory -> int -> int -> unit
val delete_hd : 'a buffer -> int -> unit
delete_hd b n
: Deletes n
bytes from the beginning of the buffer.
This means that the start
index is increased by n
.val clear : 'a buffer -> unit
val header : 'a buffer -> 'a
val descr_of_buffer : 'a buffer -> 'a buffer_descr
val buffer_of_descr : Netmcore.res_id ->
'a buffer_descr -> 'a buffer
val heap : 'a buffer -> Obj.t Netmcore_heap.heap