Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

ustl::memblock Class Reference
[Memory Management]

Allocated memory block. More...

#include <ustl.h>

Inheritance diagram for ustl::memblock:

ustl::memlink ustl::cmemlink ustl::string ustl::vector< T > ustl::vector< pair< K, V > > ustl::list< T > ustl::multiset< T > ustl::set< T > ustl::map< K, V > ustl::multimap< K, V > List of all members.

Public Member Functions

 memblock (void)
 Allocates 0 bytes for the internal block.
 memblock (const void *p, size_type n)
 links to p, n. Data can not be modified and will not be freed.
 memblock (size_type n)
 Allocates n bytes for the internal block.
 memblock (const cmemlink &b)
 Links to what b is linked to.
 memblock (const memlink &b)
 Links to what b is linked to.
 memblock (const memblock &b)
 Links to what b is linked to.
virtual ~memblock (void)
const memblockoperator= (const cmemlink &b)
 Allocates enough space and copies the contents of b.
const memblockoperator= (const memlink &b)
 Allocates enough space and copies the contents of b.
const memblockoperator= (const memblock &b)
 Allocates enough space and copies the contents of b.
void assign (const void *p, size_type n)
 Copies data from p, n.
void assign (const cmemlink &l)
 Copies data from l.
void swap (memblock &l)
 Swaps the contents with l.
void reserve (size_type newSize, bool bExact=true)
 Reallocates internal block to hold at least newSize bytes.
void resize (size_type newSize, bool bExact=true)
 resizes the block to newSize bytes, reallocating if necessary.
iterator insert (iterator start, size_type size)
 Shifts the data in the linked block from start to start + n.
iterator erase (iterator start, size_type size)
 Shifts the data in the linked block from start + n to start.
void pop_back (void)
 Removes the last element (elementSize() bytes).
void clear (void)
 Resizes the block to 0.
void deallocate (void)
 Frees internal data.
void manage (void *p, size_type n)
void manage (memlink &l)
 Assumes control over block pointed to by l.
size_type capacity (void) const
 Returns the number of bytes allocated.
virtual void unlink (void)
 Unlinks object.
size_type max_size (void) const
 Returns the maximum possible size of the block.
void read (istream &is)
 Reads the object from stream s.
void read_file (const char *filename)
 Reads the entire file "filename".
bool is_linked (void) const
 Returns true if the storage is linked, false if allocated.

Static Public Attributes

const size_type c_PageSize = 64
 The default minimum allocation unit.

Protected Member Functions

virtual size_type minimumFreeCapacity (void) const
 Do not use or override this! It exists only for implementing #string.

Detailed Description

Allocated memory block.

Adds memory management capabilities to memlink. Uses malloc and realloc to maintain the internal pointer, but only if allocated using members of this class, or if linked to using the Manage() member function. Managed memory is automatically freed in the destructor.


Constructor & Destructor Documentation

ustl::memblock::~memblock void   )  [virtual]
 

Frees internal data, if appropriate Only if the block was allocated using resize, or linked to using Manage, will it be freed. Also, Derived classes should call DestructBlock from their destructor, because upstream virtual functions are unavailable at this point and will not be called automatically.


Member Function Documentation

void ustl::memblock::manage void *  p,
size_type  n
 

Assumes control of the memory block p of size n. The block assigned using this function will be freed in the destructor.

void ustl::memblock::reserve size_type  newSize,
bool  bExact = true
 

Reallocates internal block to hold at least newSize bytes.

Additional memory may be allocated, but for efficiency it is a very good idea to call reserve before doing byte-by-byte edit operations. The block size as returned by size() is not altered. reserve will not reduce allocated memory. If you think you are wasting space, call deallocate and start over. To avoid wasting space, use the block for only one purpose, and try to get that purpose to use similar amounts of memory on each iteration.


The documentation for this class was generated from the following files:
Generated on Mon Jan 17 14:35:02 2005 for uSTL by 1.3.9 Doxygen Hosted on SourceForge.net