03.01.2013 Views

Chapter 1

Chapter 1

Chapter 1

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Figure 8.1<br />

CBufFlat, which puts all the bytes in a single heap cell. This means that access to any byte<br />

is quick (it just adds the byte index to the beginning of the buffer). However, memory<br />

allocation can be inefficient, so that it might not be possible to expand the buffer when<br />

desired, even though there may be more than enough bytes of unused heap available.<br />

CBufSeg, which puts the bytes in multiple heap cells, each of which is a segment of the<br />

buffer. For large buffers that are constantly changing in size, and where insertions and<br />

deletions part-way through the buffer are frequent, segmented buffers are much more<br />

efficient than flat buffers. Finding a particular byte theoretically requires a walk of the entire<br />

segment structure: CBufSeg caches a reference to the last-used byte, which speeds up<br />

most operations.<br />

The buffers example illustrates the functions available. The mainL()function is as<br />

follows:<br />

void mainL()<br />

{<br />

CBufBase* buf=CBufSeg::NewL(4);<br />

CleanupStack::PushL(buf);<br />

//<br />

_LIT8(KTxt1,"hello!");<br />

buf->InsertL(0,KTxt1);<br />

printBuffer(buf);

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!