DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
No More Array Errors (Part I) - Block(3C++)

Introduction to Block(3C++)

Class Block, defined in Block(3C++), strikes a happy medium between fully manual and fully automatic reallocation by providing member function reserve() that clients can call to guarantee the validity of an index. Except when reallocation is necessary, the function is extremely economical, costing only one inline instruction. The following code, which uses a Block, is functionally equivalent to the code in the section, ``What is array reallocation?''.

       #include <Block.h>
   

int size,index; ... Block<int> b(size); ... b.reserve(index); // guarantees b[index] is a // valid cell b[index] = 10;

Blocks are nothing magic; they simply hide the bookkeeping details like those that cluttered the example in the section, ``What is array reallocation?''. They also provide a few extra bells and whistles that make working with arrays safer and more convenient. This short tutorial explains how Blocks work and how to exploit this knowledge to write simple, clean, and efficient programs---without array reallocation errors!


Next topic: Creating Blocks of a Given Size
Previous topic: What is array reallocation?

© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004