ustl::memblock Class Reference
[Memory Management]

Allocated memory block. More...

#include <ustl.h>

Inheritance diagram for ustl::memblock:

ustl::memlink ustl::cmemlink ustl::string

List of all members.


Public Member Functions

 memblock (const void *p, size_type n)
 memblock (size_type n)
 memblock (const cmemlink &b)
 memblock (const memlink &b)
 memblock (const memblock &b)
virtual void unlink (void) throw ()
void assign (const cmemlink &l)
const memblockoperator= (const cmemlink &l)
const memblockoperator= (const memlink &l)
const memblockoperator= (const memblock &l)
void swap (memblock &l)
void assign (const void *p, size_type n)
 Copies data from p, n.
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 clear (void)
size_type capacity (void) const
bool is_linked (void) const
size_type max_size (void) const
void manage (memlink &l)
void deallocate (void) throw ()
 Frees internal data.
void manage (void *p, size_type n)
void copy_link (void)
 "Instantiate" a linked block by allocating and copying the linked data.
void read (istream &is)
 Reads the object from stream s.
void read_file (const char *filename)
 Reads the entire file "filename".

Protected Member Functions

virtual size_type minimumFreeCapacity (void) const __attribute__((const )) throw ()

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.


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.

References ustl::memlink::link().

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.

References ustl::Align(), ustl::copy_n(), ustl::memlink::link(), and ustl::min().

Referenced by ustl::ostringstream::overflow(), read_file(), resize(), and ustl::string::vformat().


The documentation for this class was generated from the following files:

Generated on Tue Aug 4 13:26:45 2009 for uSTL by 1.5.9 Doxygen Hosted on SourceForge.net