Teuchos::Workspace< T > Class Template Reference
[Set of utilities for allocating temporary workspace.]

Templated class for workspace creation. More...

#include <Teuchos_Workspace.hpp>

List of all members.

Public Member Functions

 Workspace (WorkspaceStore *workspace_store, size_t num_elements, bool call_constructors=true)
 Allocates a num_elements array of temporary objects.
 ~Workspace ()
 The destructor on the elements will only be called if call_constructors == true was passed to the constructor.
size_t size () const
 Return the number of elements in the array.
T & operator[] (size_t i)
 Non-const zero based element access.
const T & operator[] (size_t i) const
 Const zero based element access.


Detailed Description

template<class T>
class Teuchos::Workspace< T >

Templated class for workspace creation.

Objects of this type are what should be created by the user instead of RawWorkspace objects since this class will properly initialize memory using placement new and allows typed operator[] access to the array elements. The default constructor, copy constructor and assignment operations are not allowed and objects can not be allocated with new.

It is important to note that the constructors and destructors will only be called if call_constructors=true (the default) is passed to the consructor Workspace(). For build-in types that do not need constructors and destructors called, the client should pass in call_constructors=false . Otherwise we would have to call constructors and destructors on all of the memory and that could considerably slow things down.

With simple built-in data types (i.e. call_constructors=false) the cost of creating and destroying one of these objects should be O(1) independent of how much data is requested. This is true as long as no dynamic memory has to be allocated (this is determined the object workspace_store passed to the constructor Workspace()).

Definition at line 163 of file Teuchos_Workspace.hpp.


Constructor & Destructor Documentation

template<class T>
Teuchos::Workspace< T >::Workspace ( WorkspaceStore workspace_store,
size_t  num_elements,
bool  call_constructors = true 
) [inline]

Allocates a num_elements array of temporary objects.

Parameters:
workspace_store [in] Pointer to the workspace object to get the memory from. This can be NULL in which case new T[] and delete [] will be used instead.
num_elements [in] The number of bytes to allocate.
call_consructors [in] If true then constructors and destructors will be called on the allocated memory.
Preconditions:

Postconditons:

When this object is created the workspace_store object will be used to get the raw memory if workspace_store != NULL. If workspace_store == NULL || workspace_store->num_bytes_remaining() < sizeof(T)*num_elements then this memory will have to be dynamically allocated. The memory is default initialized (or uninitialized) using placement new. The constructor will only be called with placement new if call_constructor == ture. Otherwise, the memory will be left uninitlaized. This is okay for integral types like double and int but not okay for class types like std::string etc.

Definition at line 326 of file Teuchos_Workspace.hpp.

template<class T>
Teuchos::Workspace< T >::~Workspace (  )  [inline]

The destructor on the elements will only be called if call_constructors == true was passed to the constructor.

Definition at line 338 of file Teuchos_Workspace.hpp.


Member Function Documentation

template<class T>
size_t Teuchos::Workspace< T >::size (  )  const [inline]

Return the number of elements in the array.

Definition at line 350 of file Teuchos_Workspace.hpp.

template<class T>
T & Teuchos::Workspace< T >::operator[] ( size_t  i  )  [inline]

Non-const zero based element access.

Preconditions:

Definition at line 357 of file Teuchos_Workspace.hpp.

template<class T>
const T & Teuchos::Workspace< T >::operator[] ( size_t  i  )  const [inline]

Const zero based element access.

Preconditions:

Definition at line 367 of file Teuchos_Workspace.hpp.


The documentation for this class was generated from the following file:
Generated on Tue Oct 20 12:45:27 2009 for Teuchos - Trilinos Tools Package by doxygen 1.4.7