Public Member Functions | Protected Member Functions | List of all members
ustl::memblock Class Reference

Allocated memory block. More...

#include <ustl.h>

Inheritance diagram for ustl::memblock:
ustl::memlink ustl::cmemlink ustl::string

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) noexcept override
void assign (const cmemlink &l)
const memblockoperator= (const cmemlink &l)
const memblockoperator= (const memlink &l)
const memblockoperator= (const memblock &l)
void swap (memblock &l) noexcept
void assign (const void *p, size_type n)
 Copies data from p, n.
void reserve (size_type newSize, bool bExact=false)
 Reallocates internal block to hold at least newSize bytes. More...
void resize (size_type newSize, bool bExact=true)
 resizes the block to newSize bytes, reallocating if necessary.
iterator insert (const_iterator start, size_type size)
 Shifts the data in the linked block from start to start + n.
iterator erase (const_iterator start, size_type size)
 Shifts the data in the linked block from start + n to start.
void clear (void) noexcept
size_type capacity (void) const
bool is_linked (void) const
size_type max_size (void) const
void manage (memlink &l)
void deallocate (void) noexcept
 Frees internal data.
void shrink_to_fit (void)
 Reduces capacity to match size.
void manage (void *p, size_type n) noexcept
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".
 memblock (memblock &&b)
memblockoperator= (memblock &&b)

Protected Member Functions

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

Additional Inherited Members

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.

void ustl::memblock::reserve ( size_type  newSize,
bool  bExact = false 

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::copy_n(), ustl::min(), and ustl::NextPow2().

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

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

Generated on Mon Sep 28 2015 17:58:50 for uSTL by Doxygen 1.8.10