The Memory1D class is a templated class to handle 1 dimensional memory. It basically
allows to allocate and deallocate memory chunks, and provides an item based [...] access
operator. The whole class is item based. This means that all sizes and positions (indexes)
are interpreted as number of items.
Memory1D was designed to be the base class for all 1 dimensional containers. Thus it
provides a very simplified public interface (construction, destruction, and data access),
and a more complete set of protected functions, which allow derived classes to do their
job.
Synopsis
#include <lyric/Memory1D.hpp>
template <class MIT>
class Memory1D : private Memory<MIT>
{
public:
~Memory1D ();
Memory1D ();
Memory1D (const Memory1D& block)
throw (Exception::Memory::Alloc);
Memory1D (Size size)
throw (Exception::Memory::Alloc);
MIT& operator [] (Size index)
throw (Exception::Memory::Range);
const MIT& operator [] (Size index) const
throw (Exception::Memory::Range);
Size size () const;
protected:
void create (Size size)
throw (Exception::Memory::Alloc);
void create (Size size, const MIT* items)
throw (Exception::Memory::Alloc);
void resize (Size newsize)
throw (Exception::Memory::Alloc);
void destroy ();
void fill (const MIT& item);
void clone (const Memory1D& block)
throw (Exception::Memory::Alloc);
void move (Size size, Size src, Size dest)
throw (Exception::Memory::Move);
private:
Memory1D<MIT> & operator = (const Memory1D& block)
throw (Exception::Memory::Alloc);
};
Description
-
˜Memory1D () -
Destroys this container. Releases all memory resources used by this container
and the stored items.
-
Memory1D () -
Constructs this container as an empty container. Its size is set to zero and
no space to store items is allocated.
-
Memory1D (const Memory1D& block) -
Constructs this container from the given block container. All properties and items
stored in the block container are copied into this container.
-
Exception::Memory::Alloc
- is thrown if not enough memory is found to store
block.size() items in this container.
-
Memory1D (Size size) -
Constructs this container with the gien initial size. The size is set and space to
store size items is allocated.
-
Exception::Memory::Alloc
- is thrown if not enough memory is found to store
size items in this container.
-
MIT& operator [...] (Size index) -
Returns a reference to the item stored at position index in this container. This
operator can be used as left or right hand value. This means one can as well read as
write an item in this container.
-
Exception::Memory::Range
- is thrown if the given index is out of this
container’s size, and only if the -DO_RANGE_CHECK is given to the
compiler, resp. if O_RANGE_CHECK is defined.
-
const MIT& operator [...] (Size index) const -
Returns an immutable reference to the item stored at position index in this
container. This operator can only be used as right hand value. This means one can
only read an item from this container.
-
Exception::Memory::Range
- is thrown if the given index is out of this
container’s size, and only if the -DO_RANGE_CHECK is given to the
compiler, resp. if O_RANGE_CHECK is defined.
-
Size size () const -
Returns the number of items this container can store.
-
void create (Size size) -
Protected
Creates this container with the new given size. This operation is destructive in the
sense that items previously stored in this are deleted.
-
Exception::Memory::Alloc
- is thrown if not enough memory is found to store
size items.
-
void create (Size size, const MIT* items) -
Protected
Creates this container from a memory block pointed by items, with a given size.
This function first reserves memory for size items, then copies size items from the
memory block pointed by items into this container. This function is provided to
clone C like containers into LYRIC like containers.
-
Exception::Memory::Alloc
- is thrown if not enough memory is found to store
size items.
-
void resize (Size newsize) -
Protected
Resizes this container such that it can store newsize items. This method is only
destructive as far as the new size is smaller than the size this container was
before the call. In this case only items from zero to newsize are kept in this
container. During execution of this method items are eventually copied
around. However LYRIC’s implementation is optimized with fast memory
copies when it can thanks to the fastmemops function, it will copy items
in C++ fashion, eventually using a lot of temporary memory and CPU
resources.
-
Exception::Memory::Alloc
- is thrown if not enough memory is found to store
newsize items.
-
void destroy () -
Protected
Destroys all items stored in this container. This method releases memory resources
and sets the size to zero. The C++ object itself is not destroyed, and can be reused
after having called the create method.
-
void fill (const MIT& item) -
Protected
Sets all items stored in this container to the given item value.
-
void clone (const Memory1D& block) -
Protected
Clones the given memory block container into this container. All properties and
items stored in block are copied into this container.
-
Exception::Memory::Alloc
- is thrown if not enough memory is found to store
block.size() items.
-
void move (Size size, Size src, Size dest) -
Protected
Moves size items from the src index to the dest index in this container. LYRIC
checks if dest>src or src>dest to decide if it does a left-to-right or a right-to-left
copy, in order to not loose items during the move process.
-
Exception::Memory::Move
- is thrown if dest+size>this.size(), or if
src+size>this.size(), depending whether dest>src or src>dest.