STXXL  1.4-dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
stxxl::swappable_block< ValueType, BlockSize > Class Template Reference

Detailed Description

template<typename ValueType, unsigned BlockSize>
class stxxl::swappable_block< ValueType, BlockSize >

Virtualization of a block of data. Holds information for allocating and swapping. To use in cooperation with block_scheduler.

A swappable_block can be uninitialized, i.e. it holds no data. When access is required, is has to be acquired first, and released afterwards, so it can be swapped in and out as required. If the stored data is no longer needed, it can get uninitialized, freeing both internal and external memory.

Template Parameters
ValueTypetype of contained objects (POD with no references to internal memory).
BlockSizeNumber of objects in one block. BlockSize*sizeof(ValueType) must be divisible by 4096.

Definition at line 36 of file block_scheduler.h.

+ Inheritance diagram for stxxl::swappable_block< ValueType, BlockSize >:
+ Collaboration diagram for stxxl::swappable_block< ValueType, BlockSize >:

Public Types

typedef
internal_block_type::bid_type 
external_block_type
 
typedef typed_block
< raw_block_size, ValueType > 
internal_block_type
 

Public Member Functions

 swappable_block ()
 Create in uninitialized state. More...
 
 ~swappable_block ()
 
internal_block_typeacquire ()
 Acquire the block, i.e. add a reference. Has to be internal. More...
 
void attach_internal_block (internal_block_type *iblock)
 Attach an internal_block, making the block internal. Has to be not internal. More...
 
request_ptr clean_async (completion_handler on_cmpl=completion_handler())
 Write asyncronusly from internal_block to external_block if necessary. More...
 
void clean_sync ()
 Write synchronously from internal_block to external_block if necessary. More...
 
internal_block_typedeinitialize ()
 Bring the block in uninitialized state, freeing external and internal memory. Returns a pointer to the internal_block, NULL if it had none. More...
 
internal_block_typedetach_internal_block ()
 Detach the internal_block. Writes to external_block if necessary. Has to be evictable. More...
 
external_block_type extract_external_block ()
 Extract the swappable_blocks data in an external_block. The block gets uninitialized. More...
 
void fill_default ()
 Fill block with default data, is supposed to be overwritten by subclass. Has to be internal. More...
 
const internal_block_typeget_internal_block () const
 Get a reference to the data-block. Has to be acquired. More...
 
internal_block_typeget_internal_block ()
 Get a reference to the data-block. Has to be acquired. More...
 
bool has_external_block () const
 If it has an external_block. More...
 
void initialize (external_block_type eblock)
 Set the external_block that holds the swappable_block's data. The block gets initialized with it. More...
 
bool is_acquired () const
 If it is acquired. More...
 
bool is_dirty () const
 If the external_block does not hold valid data. More...
 
bool is_evictable () const
 If it holds an internal_block but does not need it. More...
 
bool is_external () const
 If it has an external_block that holds valid data. More...
 
bool is_initialized () const
 If it has some valid data (in- or external). More...
 
bool is_internal () const
 If it has an internal_block. The internal_block implicitly holds valid data. More...
 
bool make_dirty_if (const bool make_dirty)
 Invalidate external data if true. More...
 
request_ptr read_async (completion_handler on_cmpl=completion_handler())
 Read asyncronusly from external_block to internal_block. Has to be internal and have an external_block. More...
 
void read_sync ()
 Read synchronously from external_block to internal_block. Has to be internal and have an external_block. More...
 
void release ()
 Release the block, i.e. subduct a reference. Has to be acquired. More...
 

Protected Member Functions

void free_external_block ()
 
void get_external_block ()
 

Protected Attributes

bool dirty
 
external_block_type external_data
 
internal_block_typeinternal_data
 external_data.valid if no associated space on disk More...
 
int_type reference_count
 

Static Protected Attributes

static unsigned_type disk_allocation_offset = 0
 
static const unsigned_type raw_block_size = BlockSize * sizeof(ValueType)
 

Member Typedef Documentation

template<typename ValueType, unsigned BlockSize>
typedef internal_block_type::bid_type stxxl::swappable_block< ValueType, BlockSize >::external_block_type

Definition at line 43 of file block_scheduler.h.

template<typename ValueType, unsigned BlockSize>
typedef typed_block<raw_block_size, ValueType> stxxl::swappable_block< ValueType, BlockSize >::internal_block_type

Definition at line 42 of file block_scheduler.h.

Constructor & Destructor Documentation

template<typename ValueType, unsigned BlockSize>
stxxl::swappable_block< ValueType, BlockSize >::swappable_block ( )
inline

Create in uninitialized state.

valid

Definition at line 64 of file block_scheduler.h.

template<typename ValueType, unsigned BlockSize>
stxxl::swappable_block< ValueType, BlockSize >::~swappable_block ( )
inline

Definition at line 67 of file block_scheduler.h.

Member Function Documentation

template<typename ValueType, unsigned BlockSize>
internal_block_type& stxxl::swappable_block< ValueType, BlockSize >::acquire ( )
inline

Acquire the block, i.e. add a reference. Has to be internal.

Returns
A reference to the data-block.

Definition at line 107 of file block_scheduler.h.

template<typename ValueType, unsigned BlockSize>
void stxxl::swappable_block< ValueType, BlockSize >::attach_internal_block ( internal_block_type iblock)
inline

Attach an internal_block, making the block internal. Has to be not internal.

Definition at line 179 of file block_scheduler.h.

template<typename ValueType, unsigned BlockSize>
request_ptr stxxl::swappable_block< ValueType, BlockSize >::clean_async ( completion_handler  on_cmpl = completion_handler())
inline

Write asyncronusly from internal_block to external_block if necessary.

Returns
A request pointer to the I/O, an invalid request pointer if not necessary.

Definition at line 157 of file block_scheduler.h.

template<typename ValueType, unsigned BlockSize>
void stxxl::swappable_block< ValueType, BlockSize >::clean_sync ( )
inline

Write synchronously from internal_block to external_block if necessary.

Definition at line 171 of file block_scheduler.h.

template<typename ValueType, unsigned BlockSize>
internal_block_type* stxxl::swappable_block< ValueType, BlockSize >::deinitialize ( )
inline

Bring the block in uninitialized state, freeing external and internal memory. Returns a pointer to the internal_block, NULL if it had none.

Returns
A pointer to the freed internal_block, NULL if it had none.

Definition at line 199 of file block_scheduler.h.

template<typename ValueType, unsigned BlockSize>
internal_block_type* stxxl::swappable_block< ValueType, BlockSize >::detach_internal_block ( )
inline

Detach the internal_block. Writes to external_block if necessary. Has to be evictable.

Returns
A pointer to the internal_block.

Definition at line 187 of file block_scheduler.h.

template<typename ValueType, unsigned BlockSize>
external_block_type stxxl::swappable_block< ValueType, BlockSize >::extract_external_block ( )
inline

Extract the swappable_blocks data in an external_block. The block gets uninitialized.

Returns
The external_block that holds the swappable_block's data.

Definition at line 222 of file block_scheduler.h.

template<typename ValueType, unsigned BlockSize>
void stxxl::swappable_block< ValueType, BlockSize >::fill_default ( )
inline

Fill block with default data, is supposed to be overwritten by subclass. Has to be internal.

Definition at line 136 of file block_scheduler.h.

template<typename ValueType, unsigned BlockSize>
void stxxl::swappable_block< ValueType, BlockSize >::free_external_block ( )
inlineprotected

Definition at line 56 of file block_scheduler.h.

template<typename ValueType, unsigned BlockSize>
void stxxl::swappable_block< ValueType, BlockSize >::get_external_block ( )
inlineprotected

Definition at line 53 of file block_scheduler.h.

template<typename ValueType, unsigned BlockSize>
const internal_block_type& stxxl::swappable_block< ValueType, BlockSize >::get_internal_block ( ) const
inline

Get a reference to the data-block. Has to be acquired.

Definition at line 122 of file block_scheduler.h.

template<typename ValueType, unsigned BlockSize>
internal_block_type& stxxl::swappable_block< ValueType, BlockSize >::get_internal_block ( )
inline

Get a reference to the data-block. Has to be acquired.

Definition at line 129 of file block_scheduler.h.

template<typename ValueType, unsigned BlockSize>
bool stxxl::swappable_block< ValueType, BlockSize >::has_external_block ( ) const
inline

If it has an external_block.

Definition at line 78 of file block_scheduler.h.

template<typename ValueType, unsigned BlockSize>
void stxxl::swappable_block< ValueType, BlockSize >::initialize ( external_block_type  eblock)
inline

Set the external_block that holds the swappable_block's data. The block gets initialized with it.

Parameters
eblockThe external_block holding initial data.

Definition at line 214 of file block_scheduler.h.

template<typename ValueType, unsigned BlockSize>
bool stxxl::swappable_block< ValueType, BlockSize >::is_acquired ( ) const
inline

If it is acquired.

Definition at line 86 of file block_scheduler.h.

template<typename ValueType, unsigned BlockSize>
bool stxxl::swappable_block< ValueType, BlockSize >::is_dirty ( ) const
inline

If the external_block does not hold valid data.

Definition at line 74 of file block_scheduler.h.

template<typename ValueType, unsigned BlockSize>
bool stxxl::swappable_block< ValueType, BlockSize >::is_evictable ( ) const
inline

If it holds an internal_block but does not need it.

Definition at line 90 of file block_scheduler.h.

template<typename ValueType, unsigned BlockSize>
bool stxxl::swappable_block< ValueType, BlockSize >::is_external ( ) const
inline

If it has an external_block that holds valid data.

Definition at line 82 of file block_scheduler.h.

template<typename ValueType, unsigned BlockSize>
bool stxxl::swappable_block< ValueType, BlockSize >::is_initialized ( ) const
inline

If it has some valid data (in- or external).

Definition at line 94 of file block_scheduler.h.

template<typename ValueType, unsigned BlockSize>
bool stxxl::swappable_block< ValueType, BlockSize >::is_internal ( ) const
inline

If it has an internal_block. The internal_block implicitly holds valid data.

Definition at line 70 of file block_scheduler.h.

template<typename ValueType, unsigned BlockSize>
bool stxxl::swappable_block< ValueType, BlockSize >::make_dirty_if ( const bool  make_dirty)
inline

Invalidate external data if true.

Returns
is_dirty()

Definition at line 99 of file block_scheduler.h.

template<typename ValueType, unsigned BlockSize>
request_ptr stxxl::swappable_block< ValueType, BlockSize >::read_async ( completion_handler  on_cmpl = completion_handler())
inline

Read asyncronusly from external_block to internal_block. Has to be internal and have an external_block.

Returns
A request pointer to the I/O.

Definition at line 140 of file block_scheduler.h.

template<typename ValueType, unsigned BlockSize>
void stxxl::swappable_block< ValueType, BlockSize >::read_sync ( )
inline

Read synchronously from external_block to internal_block. Has to be internal and have an external_block.

Definition at line 152 of file block_scheduler.h.

template<typename ValueType, unsigned BlockSize>
void stxxl::swappable_block< ValueType, BlockSize >::release ( )
inline

Release the block, i.e. subduct a reference. Has to be acquired.

Definition at line 115 of file block_scheduler.h.

Member Data Documentation

template<typename ValueType, unsigned BlockSize>
bool stxxl::swappable_block< ValueType, BlockSize >::dirty
protected

Definition at line 48 of file block_scheduler.h.

template<typename ValueType, unsigned BlockSize>
unsigned_type stxxl::swappable_block< ValueType, BlockSize >::disk_allocation_offset = 0
staticprotected

Definition at line 51 of file block_scheduler.h.

template<typename ValueType, unsigned BlockSize>
external_block_type stxxl::swappable_block< ValueType, BlockSize >::external_data
protected

Definition at line 46 of file block_scheduler.h.

template<typename ValueType, unsigned BlockSize>
internal_block_type* stxxl::swappable_block< ValueType, BlockSize >::internal_data
protected

external_data.valid if no associated space on disk

Definition at line 47 of file block_scheduler.h.

template<typename ValueType, unsigned BlockSize>
const unsigned_type stxxl::swappable_block< ValueType, BlockSize >::raw_block_size = BlockSize * sizeof(ValueType)
staticprotected

Definition at line 39 of file block_scheduler.h.

template<typename ValueType, unsigned BlockSize>
int_type stxxl::swappable_block< ValueType, BlockSize >::reference_count
protected

Definition at line 49 of file block_scheduler.h.


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