From: Kevin Atkinson (kevin_at_[hidden])
Date: 2003-03-04 05:05:08
Is there any interest in a vector like container which is designed to make
working with raw memory easy. It is different from a vector<char> (with
the additional assumption that the objects are stored in memory
sequentially) is the following ways:
The integrator is defined to be a pointer to make working with functions
that use raw memory easy.
It can use a specific range of user supplied memory for its storage.
When using user memory it will never attempt to allocate more memory.
capacity() == max_size().
Any function which takes a range:
(const_iterator start, const_iterator stop)
can also take a void pointer and a size ie:
(const void * data, size_type size)
Any function which takes an iterator to represent a position within
the exiting object can also take an offset. If two iterators are
used to represent a range than an offset and a size can also be used.
Like vector, push_back(), and pop_back() or constant time operations if
storage is available. However, unlike vector, pop_front() is a
constant time operation and push_front() can be made to be constant
support for replacing one range with another while moving the minimal
amount of memory possible:
replace(iterator start, iterator_stop,
const_iterator rstart, const_iterator rstop)
A special member function
template <typename U> U * datap(size_type pos = 0)
which allows treating the memory as another type without an ugly
reinterpret_cast. This statement is equivalent to
reinterpret_cast<U *>(...) + pos
My implementation is not a template. It uses new and delete for memory
allocation and the data type is "unsigned char". Since the main goal for
this class was working with raw memory and not an array of objects I
decided not to make it a template.
Some of the features of Buffer might be useful for a more general purpose
vector, such as the replace method and the ability to use user memory.
If people are really interested I will post my code.
I wrote it to make working with Berkeley database and sending network
messages as painless as possible.
Let me know.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk