[Gambas-user] file question

Christopher Brian Jack brian at ...1334...
Wed Oct 11 18:40:45 CEST 2006


On Wed, 11 Oct 2006, Christopher Brian Jack wrote:

> The solution to your problem is a ring buffer.
>
> To use a ring buffer split your main buffer into sequential chunks,
> maintaining a head and tail position in the buffer.  If the head and tail
> indices are zero-based (0 indicates the first chunk) then you can use x
> MOD NumberOfChunks to get the wraparound effect needed for the index
> arithmetic.  The explanation below uses MOD and hence assumes zero-based
> indices.

If you want to implement the ring buffer as a file abstraction then pick
an appropriate blocksize and use head*blocksize or tail*blocksize (as
appropriate to the operation) as arguments to seeking in the file.
You'll need to add a special lastblock value which remembers the size of
the very last block of the file (which typically isn't going to be a nice
multiple of the chosen blocksize).  When accessing on the highest index
the client using the buffer needs to be informed about the size of the
chunk being read (last part of the file) is less than the
buffer's blocksize.

.=================================================.
|  Christopher BRIAN Jack aka "Gau of the Veldt"  |
+================================================='
| oevna at ...1544...
`=================================================-
Hi Spambots, my email address is sputnik at ...1334...
Hi Humans, my email address uses rot13 cipher





More information about the User mailing list