Hi,
If we are going to handle binary data, I guess we need an utility
class MemBuff ('memory buffer').
See attached file for an initial implementation. I would like to
avoid memcpy on each MemBuf copy constructor call. We are facing now
a 'buffer ownership' problem (i.e.: when should the buffer be freed in
MemBuff destructor?).
We could use reference counting, but that would require to use an
underlying object, and all MemBuff simply have a pointer to the true
object.
Another possibility (a little overhead in memory & CPU) is to use a
circular doubly linked lists of MemBuf objects. All MemBuf objects
that point to the same buffer, would be in the same 'ring'. When the
last element of a ring is destroyed, the buffer is destroyed.
Any other ideas? The first requires another class, while the second
requires more CPU & memory. So I guess the first is the best.
How does this sound to you?
Cheers,
--
Gonzalo A. Arana
|