Buffer for page-aligned I/O
This kind of buffer uses page-aligned bigarrays. Data can only be added to the end, or deleted at the beginning of the buffer.
The idea of this buffer is that input data is added to the last
page of the buffer only (with
add_inplace). If then all previous
input was already a multiple of the page size, it is ensured that
the new input is added at a page boundary. This kind of input operation
can often be accelerated by the OS ("zero copy network I/O").
add_inplace b f: Calls
f m pos len where
m is the last page
of the buffer, and
pos is the first free byte on the page, and
len is the number of free bytes on the page. The function
expected to store new data in
pos+n-1 and to
n. The number
n is also returned as final result.
It is ensured that
f is called with a value of
advance b n: Marks further
n bytes in the last page of the
buffer as used. These bytes are not modified in any way - it is
expected that the user calls
page_for_additions first, and sets
n bytes to new values directly.