OpenASIP  2.0
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
PagedArray< ValueType, PageSize, DefaultValue > Class Template Reference

#include <PagedArray.hh>

Inheritance diagram for PagedArray< ValueType, PageSize, DefaultValue >:
Inheritance graph
Collaboration diagram for PagedArray< ValueType, PageSize, DefaultValue >:
Collaboration graph

Public Types

typedef ValueType * ValueTable
 Type for a set of values in a basic array type. More...
 
typedef std::vector< ValueType > ValueVector
 Type for a set of values in a std::vector container. More...
 

Public Member Functions

 PagedArray (std::size_t size)
 
virtual ~PagedArray ()
 
void write (IndexType index, const ValueTable data, std::size_t size)
 
void writeData (IndexType index, const ValueType &data)
 
ValueType readData (IndexType index)
 
void read (IndexType index, ValueVector &data, size_t size)
 
void read (IndexType index, ValueVector &data)
 
void read (IndexType index, ValueTable data, size_t size)
 
size_t allocatedMemory () const
 
void clear ()
 

Private Member Functions

void deletePages ()
 
 PagedArray (const PagedArray &)
 Copying not allowed. More...
 
PagedArrayoperator= (const PagedArray &)
 Assignment not allowed. More...
 

Private Attributes

ValueType ** pageTable_
 Storage for the data pages. Created pages are stored in table from which they are found with address / size_of_page. More...
 
std::size_t pageTableSize_
 Size of the page table. More...
 

Detailed Description

template<typename ValueType, int PageSize = DEFAULT_PAGE_SIZE, ValueType DefaultValue = static_cast<ValueType>(UNDEFINED_VALUE)>
class PagedArray< ValueType, PageSize, DefaultValue >

Models the data contained in array.

The array space is divided into pages which are allocated on-demand, that is, the first time an index in that page is accessed for a write operation. Pages are stored in a table from which they are retrieved using (address / page_size) as index. The offset within the selected page is given by (address % chunk_size). This should result in O(1) access.

This allows modeling large arrays without reserving the memory for the array if it's not accessed. The idea behind this implementation is borrowed from common (paged) virtual memory implementations of operating systems.

Please note that this container does not perform any checking for the validity of the indices due to efficiency reasons.

Definition at line 69 of file PagedArray.hh.

Member Typedef Documentation

◆ ValueTable

template<typename ValueType , int PageSize = DEFAULT_PAGE_SIZE, ValueType DefaultValue = static_cast<ValueType>(UNDEFINED_VALUE)>
typedef ValueType* PagedArray< ValueType, PageSize, DefaultValue >::ValueTable

Type for a set of values in a basic array type.

Definition at line 73 of file PagedArray.hh.

◆ ValueVector

template<typename ValueType , int PageSize = DEFAULT_PAGE_SIZE, ValueType DefaultValue = static_cast<ValueType>(UNDEFINED_VALUE)>
typedef std::vector<ValueType> PagedArray< ValueType, PageSize, DefaultValue >::ValueVector

Type for a set of values in a std::vector container.

Definition at line 76 of file PagedArray.hh.

Constructor & Destructor Documentation

◆ PagedArray() [1/2]

template<typename ValueType , int PageSize = DEFAULT_PAGE_SIZE, ValueType DefaultValue = static_cast<ValueType>(UNDEFINED_VALUE)>
PagedArray< ValueType, PageSize, DefaultValue >::PagedArray ( std::size_t  size)

◆ ~PagedArray()

template<typename ValueType , int PageSize = DEFAULT_PAGE_SIZE, ValueType DefaultValue = static_cast<ValueType>(UNDEFINED_VALUE)>
virtual PagedArray< ValueType, PageSize, DefaultValue >::~PagedArray ( )
virtual

◆ PagedArray() [2/2]

template<typename ValueType , int PageSize = DEFAULT_PAGE_SIZE, ValueType DefaultValue = static_cast<ValueType>(UNDEFINED_VALUE)>
PagedArray< ValueType, PageSize, DefaultValue >::PagedArray ( const PagedArray< ValueType, PageSize, DefaultValue > &  )
private

Copying not allowed.

Member Function Documentation

◆ allocatedMemory()

template<typename ValueType , int PageSize = DEFAULT_PAGE_SIZE, ValueType DefaultValue = static_cast<ValueType>(UNDEFINED_VALUE)>
size_t PagedArray< ValueType, PageSize, DefaultValue >::allocatedMemory ( ) const

◆ clear()

template<typename ValueType , int PageSize = DEFAULT_PAGE_SIZE, ValueType DefaultValue = static_cast<ValueType>(UNDEFINED_VALUE)>
void PagedArray< ValueType, PageSize, DefaultValue >::clear ( )

◆ deletePages()

template<typename ValueType , int PageSize = DEFAULT_PAGE_SIZE, ValueType DefaultValue = static_cast<ValueType>(UNDEFINED_VALUE)>
void PagedArray< ValueType, PageSize, DefaultValue >::deletePages ( )
private

◆ operator=()

template<typename ValueType , int PageSize = DEFAULT_PAGE_SIZE, ValueType DefaultValue = static_cast<ValueType>(UNDEFINED_VALUE)>
PagedArray& PagedArray< ValueType, PageSize, DefaultValue >::operator= ( const PagedArray< ValueType, PageSize, DefaultValue > &  )
private

Assignment not allowed.

◆ read() [1/3]

template<typename ValueType , int PageSize = DEFAULT_PAGE_SIZE, ValueType DefaultValue = static_cast<ValueType>(UNDEFINED_VALUE)>
void PagedArray< ValueType, PageSize, DefaultValue >::read ( IndexType  index,
ValueTable  data,
size_t  size 
)

◆ read() [2/3]

template<typename ValueType , int PageSize = DEFAULT_PAGE_SIZE, ValueType DefaultValue = static_cast<ValueType>(UNDEFINED_VALUE)>
void PagedArray< ValueType, PageSize, DefaultValue >::read ( IndexType  index,
ValueVector data 
)

◆ read() [3/3]

template<typename ValueType , int PageSize = DEFAULT_PAGE_SIZE, ValueType DefaultValue = static_cast<ValueType>(UNDEFINED_VALUE)>
void PagedArray< ValueType, PageSize, DefaultValue >::read ( IndexType  index,
ValueVector data,
size_t  size 
)

◆ readData()

template<typename ValueType , int PageSize = DEFAULT_PAGE_SIZE, ValueType DefaultValue = static_cast<ValueType>(UNDEFINED_VALUE)>
ValueType PagedArray< ValueType, PageSize, DefaultValue >::readData ( IndexType  index)

◆ write()

template<typename ValueType , int PageSize = DEFAULT_PAGE_SIZE, ValueType DefaultValue = static_cast<ValueType>(UNDEFINED_VALUE)>
void PagedArray< ValueType, PageSize, DefaultValue >::write ( IndexType  index,
const ValueTable  data,
std::size_t  size 
)

◆ writeData()

template<typename ValueType , int PageSize = DEFAULT_PAGE_SIZE, ValueType DefaultValue = static_cast<ValueType>(UNDEFINED_VALUE)>
void PagedArray< ValueType, PageSize, DefaultValue >::writeData ( IndexType  index,
const ValueType &  data 
)

Member Data Documentation

◆ pageTable_

template<typename ValueType , int PageSize = DEFAULT_PAGE_SIZE, ValueType DefaultValue = static_cast<ValueType>(UNDEFINED_VALUE)>
ValueType** PagedArray< ValueType, PageSize, DefaultValue >::pageTable_
private

Storage for the data pages. Created pages are stored in table from which they are found with address / size_of_page.

Definition at line 101 of file PagedArray.hh.

◆ pageTableSize_

template<typename ValueType , int PageSize = DEFAULT_PAGE_SIZE, ValueType DefaultValue = static_cast<ValueType>(UNDEFINED_VALUE)>
std::size_t PagedArray< ValueType, PageSize, DefaultValue >::pageTableSize_
private

Size of the page table.

Definition at line 103 of file PagedArray.hh.


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