A buffer is intended to be a temporary workspace in memory. More...
#include <fileManager.h>
Public Member Functions | |
T * | address () const |
Address of the buffer allocated. | |
buffer (size_t sz=0) | |
Constructor. Default size is 16 MB. More... | |
T & | operator[] (size_t i) |
Return the ith value. It does not perform array bounds check! | |
const T & | operator[] (size_t i) const |
Return the ith value. It does not perform array bounds check! | |
size_t | resize (size_t sz=0) |
Increase the size of the buffer. More... | |
size_t | size () const |
The number of elements in the buffer. NOT the number of bytes. | |
void | swap (buffer< T > &other) throw () |
Swap the content of two buffers. | |
~buffer () | |
Destructor. Release the memory allocated. | |
A buffer is intended to be a temporary workspace in memory.
The constructor allocates a certain amount of memory, default to 16 MB; the destructor release the memory. Its size can not be changed.
ibis::fileManager::buffer< T >::buffer | ( | size_t | sz = 0 | ) |
Constructor. Default size is 16 MB.
Constructor.
The incoming argument is the number of elements to be allocated. If it is zero, the default is to use 16 MB of space, and the number of elements is 16 million divided by the size of the element. If it fails to allocate the requested memory, it will reduce the number of elements by a half and then by a quarter for a total of seven times. If it failed all eight tries, it will set the buffer address to nil and the number of elements to zero. It also check to make sure it does not use more than 1/4th of free memory. The buffer may contain no elements at all if there is insufficient amount of memory to use. The caller should always check that buffer.size() > 0 and buffer.address() != 0.
References ibis::fileManager::bytesFree().
size_t ibis::fileManager::buffer< T >::resize | ( | size_t | sz = 0 | ) |
Increase the size of the buffer.
Increase the number of elements can be stored in the buffer to sz.
If the input size is 0, it doubles the current size. If the input value is not 0 but less than the current size, nothing is done. It return the number of elements can be stored. Since a buffer is intended to be for temporary storage, the existing content is not copied when reallocating new memory. It will not allocate more than 2GB of memory.
References ibis::fileManager::bytesFree().
Referenced by ibis::dictionary::fromASCII(), ibis::bord::column::keywordSearch(), ibis::keywords::parseTextFile(), ibis::index::bitmapReader::read(), ibis::tafel::readCSV(), ibis::tablex::readNamesAndTypes(), and ibis::tafel::readSQLStatement().