Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

Array< T > Class Template Reference

Array is a simple growable list container implemented as an array. More...

#include <array.h>

Inheritance diagram for Array< T >:

Inheritance graph
[legend]
Collaboration diagram for Array< T >:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Array (bool physical=false, Size init_capacity=0)
void init (bool physical=false, Size init_capacity=0)
Size size ()
void set_size (unsigned new_size)
Size get_capacity ()
void grow (bool set_size_too=false)
void ensure_capacity ()
T & append (T &element)
T & operator[] (unsigned index)
void clear ()

Protected Attributes

T * data
Size used_size
Size capacity
Size init_capacity
bool physical

Static Protected Attributes

const Size INITIAL_VIRTUAL_CAPACITY = 8
const Size INITIAL_PHYSICAL_CAPACITY = PAGE_SIZE / sizeof(T)

Detailed Description

template<class T>
class Array< T >

Array is a simple growable list container implemented as an array.

It can be based on either virtual or physical memory. Growing the array's capacity is performed automatically on demand.


Constructor & Destructor Documentation

template<class T>
Array< T >::Array bool  physical = false,
Size  init_capacity = 0
[inline]
 

Call init() with the given arguments.


Member Function Documentation

template<class T>
T& Array< T >::append T &  element  )  [inline]
 

Add an element to the end of the array and return a reference to it within the array.

template<class T>
void Array< T >::clear  )  [inline]
 

Clear the array and free its memory.

template<class T>
void Array< T >::ensure_capacity  )  [inline]
 

Ensure that there's enough capacity for the current used_size.

template<class T>
Size Array< T >::get_capacity  )  [inline]
 

Return the current array capacity.

template<class T>
void Array< T >::grow bool  set_size_too = false  ) 
 

Expand the array's total capacity.

If set_size_too is true, then the array's used_size will be set to the same value as the new capacity.

template<class T>
void Array< T >::init bool  physical = false,
Size  init_capacity = 0
[inline]
 

Initialize a null array of zero elements and zero capacity.

Set physical to true if the array data should be allocated from physical memory. Otherwise, leave physical false and data will be allocated from persistent virtual memory. An initial array capacity can be provided to override the default capacity.

template<class T>
T& Array< T >::operator[] unsigned  index  )  [inline]
 

Return a particular indexed element. No bounds checking is performed.

template<class T>
void Array< T >::set_size unsigned  new_size  )  [inline]
 

Set the used size of the array manually.

This is useful if you want to just start addressing individual elements of the array.

template<class T>
Size Array< T >::size  )  [inline]
 

Return the number of currently used elements.

This is distinct from the current capacity of the array.


Member Data Documentation

template<class T>
Size Array< T >::capacity [protected]
 

number of possible elements that can be used before growth is required

template<class T>
T* Array< T >::data [protected]
 

actual array elements

template<class T>
Size Array< T >::init_capacity [protected]
 

capacity to set on initialization

template<class T>
const Size Array< T >::INITIAL_PHYSICAL_CAPACITY = PAGE_SIZE / sizeof(T) [static, protected]
 

template<class T>
const Size Array< T >::INITIAL_VIRTUAL_CAPACITY = 8 [static, protected]
 

template<class T>
bool Array< T >::physical [protected]
 

whether to use physical allocator

template<class T>
Size Array< T >::used_size [protected]
 

number of elements currently in use


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

Torsion Operating System, Copyright (C) 2000-2004 Dan Helfman