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

datablock< T > Class Template Reference
[Data blocks and data views]

A datablock<T> is a block of memory, formatted to hold an array of T, with reference counting. More...

#include <datablock.h>

Collaboration diagram for datablock< T >:

Collaboration graph
[legend]
List of all members.

Public Member Functions

itype Size () const
 Returns the size of the datablock.
itype CountRefs ()
 Returns the current number of views linked to this block.
itype AddRef ()
 Informs the datablock that another view is linking to it. Returns new reference count.
itype RemoveRef ()
 Informs the datablock that a view is not linked to it anymore. Returns new reference count.
itype Resize (itype newsize)
 Changes the size of the block; returns the new size.
void CopyFrom (T *ptr)
 Copy size elements of data from a pointer. Use with caution!
void CopyFrom (T *ptr, itype max_items)
 Copy MIN(max_items,size) elements of data from a pointer. Safer than CopyFrom( T *ptr ).
void CopyFrom (datablock< T > &other)
 Copy data from another datablock. Safest and recommended.
 datablock ()
 Construct a datablock of size zero.
 datablock (itype s)
 Construct a datablock of size s.
 datablock (const datablock< T > &other)
 Construct a datablock as a copy of other.
 datablock (const datablock< T > &other, itype s)
 Construct a datablock as a copy of other, but up- or down-sizing to size s.
 ~datablock ()
 Destroy the datablock, returning its memory to the heap.

Public Attributes

T * data
 A pointer to the array of T's.

Detailed Description

template<class T>
class datablock< T >

A datablock<T> is a block of memory, formatted to hold an array of T, with reference counting.

Datablocks do the dirty work of holding the contents of Vectors and Matrices. They can be resized nondestructively (of course, reducing the size will lose some data!), and keep track of references. A dataview<T> may therefore link to a datablock without worrying about memory management; as long as the view informs the block that it is linking to it or disconnecting, the datablock will delete itself when appropriate.


Member Function Documentation

template<class T>
itype datablock< T >::Resize itype  newsize  )  [inline]
 

Changes the size of the block; returns the new size.

< When the datablock hits zero references, it will delete itself

template<class T>
void datablock< T >::CopyFrom T *  ptr  )  [inline]
 

Copy size elements of data from a pointer. Use with caution!

< If the new size is the same as the old, nothing is done. Otherwise, a new chunk of memory is allocated, and initialized to zero. As much of the old data as will fit is then copied to the new block, and the old memory is deallocated.


The documentation for this class was generated from the following file:
Generated on Wed Jun 14 22:25:27 2006 for linalg by  doxygen 1.4.4