Pike v8.0 release 1738

Class String.Buffer

Description

A buffer, used for building strings. It's conceptually similar to a string, but you can only add strings to it, and you can only get the value from it once.

There is a reason for those seemingly rather odd limitations, it makes it possible to do some optimizations that really speed things up.

You do not need to use this class unless you add very many strings together, or very large strings.

Example

For the fastest possible operation, write your code like this:

String.Buffer b = String.Buffer( );

function add = b->add;

.. call add several times in code ...

string result = b->get(); // also clears the buffer

Method create

String.Buffer String.Buffer(int initial_size)

Description

Initializes a new buffer.

If no initial_size is specified, 256 is used. If you know approximately how big the buffer will be, you can optimize the operation of add() (slightly) by passing the size to this function.