Developers.Topic.BuffersAndLengths

From Shareaza Wiki
Revision as of 18:32, 31 December 2007 by Dirtycat (talk | contribs) (Importing page from Tikiwiki)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

how to draw the little picture with a half-filled bar, a pointer to the left corner, lengths from the left to the right for filled size and total size

Buffers and Lengths

A buffer is a space of memory in the computer that a program can read from and write to. Shareaza uses a class called CBuffer to manage buffers. Three important variables define a buffer:

pBuffer The pointer to the start of the buffer in memory. nBuffer The length of space we can safely read from and write to, starting there, in bytes. nLength The length at the start of bytes we have written in the buffer.

Here's some common pointer arithmatic for buffers:

The amount of space left in the buffer is nBuffer - nLength. The memory location where we can start writing new data is pBuffer + nLength.

Here is a diagram which shows all these pointers and lengths:

File:Bufferdiagram.png