14 #ifndef STXXL_TYPED_BLOCK_HEADER
15 #define STXXL_TYPED_BLOCK_HEADER
17 #include <stxxl/bits/io/request.h>
18 #include <stxxl/bits/common/aligned_alloc.h>
19 #include <stxxl/bits/mng/bid.h>
21 #ifndef STXXL_VERBOSE_TYPED_BLOCK
22 #define STXXL_VERBOSE_TYPED_BLOCK STXXL_VERBOSE2
26 __STXXL_BEGIN_NAMESPACE
32 template <
unsigned bytes>
35 typedef unsigned char byte_type;
36 byte_type filler_array_[bytes];
39 filler_struct__() { STXXL_VERBOSE_TYPED_BLOCK(
"[" << (
void *)
this <<
"] filler_struct__ is constructed"); }
43 class filler_struct__<0>
45 typedef unsigned char byte_type;
48 filler_struct__() { STXXL_VERBOSE_TYPED_BLOCK(
"[" << (
void *)
this <<
"] filler_struct__<> is constructed"); }
52 template <
class T,
unsigned Size_>
58 typedef T & reference;
59 typedef const T & const_reference;
60 typedef type * pointer;
61 typedef pointer iterator;
62 typedef const type * const_iterator;
72 element_block() { STXXL_VERBOSE_TYPED_BLOCK(
"[" << (
void *)
this <<
"] element_block is constructed"); }
105 const_iterator
end()
const
118 template <
class T,
unsigned Size_,
unsigned RawSize_,
unsigned NB
ids_ = 0>
139 block_w_bids() { STXXL_VERBOSE_TYPED_BLOCK(
"[" << (
void *)
this <<
"] block_w_bids is constructed"); }
142 template <
class T,
unsigned Size_,
unsigned RawSize_>
154 block_w_bids() { STXXL_VERBOSE_TYPED_BLOCK(
"[" << (
void *)
this <<
"] block_w_bids<> is constructed"); }
158 template <
class T_,
unsigned RawSize_,
unsigned NB
ids_,
class InfoType_ =
void>
160 public block_w_bids<T_, ((RawSize_ - sizeof(BID<RawSize_>) * NBids_ - sizeof(InfoType_)) / sizeof(T_)), RawSize_, NBids_>
169 block_w_info() { STXXL_VERBOSE_TYPED_BLOCK(
"[" << (
void *)
this <<
"] block_w_info is constructed"); }
172 template <
class T_,
unsigned RawSize_,
unsigned NB
ids_>
174 public block_w_bids<T_, ((RawSize_ - sizeof(BID<RawSize_>) * NBids_) / sizeof(T_)), RawSize_, NBids_>
179 block_w_info() { STXXL_VERBOSE_TYPED_BLOCK(
"[" << (
void *)
this <<
"] block_w_info<> is constructed"); }
183 template <
typename BaseType_,
unsigned FillSize_ = 0>
189 filler_struct__<FillSize_> filler;
192 add_filler() { STXXL_VERBOSE_TYPED_BLOCK(
"[" << (
void *)
this <<
"] add_filler is constructed"); }
195 template <
typename BaseType_>
200 add_filler() { STXXL_VERBOSE_TYPED_BLOCK(
"[" << (
void *)
this <<
"] add_filler<> is constructed"); }
204 template <
typename Tp_,
unsigned RawSize_>
206 public add_filler<Tp_, RawSize_ - sizeof(Tp_)>
222 template <
unsigned RawSize_,
class T_,
unsigned NRef_ = 0,
class InfoType_ =
void>
224 public expand_struct<block_w_info<T_, RawSize_, NRef_, InfoType_>, RawSize_>
229 typedef T_ value_type;
230 typedef value_type & reference;
231 typedef const value_type & const_reference;
232 typedef value_type * pointer;
233 typedef pointer iterator;
234 typedef const value_type * const_pointer;
235 typedef const_pointer const_iterator;
249 STXXL_VERBOSE_TYPED_BLOCK(
"[" << (
void *)
this <<
"] typed_block is constructed");
251 assert(((
long)
this) % BLOCK_ALIGN == 0);
259 STXXL_MSG(
"[" << (
void *)
this <<
"] typed_block is copy constructed from [" << (
void *)&tb <<
"]");
272 STXXL_VERBOSE_BLOCK_LIFE_CYCLE(
"BLC:write " << FMT_BID(bid));
284 STXXL_VERBOSE_BLOCK_LIFE_CYCLE(
"BLC:read " << FMT_BID(bid));
288 static void *
operator new (
size_t bytes)
290 unsigned_type meta_info_size = bytes %
raw_size;
291 STXXL_VERBOSE1(
"typed::block operator new: Meta info size: " << meta_info_size);
293 void * result = aligned_alloc<BLOCK_ALIGN>(bytes - meta_info_size, meta_info_size);
294 #ifdef STXXL_VALGRIND_TYPED_BLOCK_INITIALIZE_ZERO
295 memset(result, 0, bytes);
297 char * tmp = (
char *)result;
299 while (tmp < ((
char *)result) + bytes)
306 static void *
operator new[] (
size_t bytes)
308 unsigned_type meta_info_size = bytes %
raw_size;
309 STXXL_VERBOSE1(
"typed::block operator new[]: Meta info size: " << meta_info_size);
311 void * result = aligned_alloc<BLOCK_ALIGN>(bytes - meta_info_size, meta_info_size);
312 #ifdef STXXL_VALGRIND_TYPED_BLOCK_INITIALIZE_ZERO
313 memset(result, 0, bytes);
315 char * tmp = (
char *)result;
317 while (tmp < ((
char *)result) + bytes)
324 static void *
operator new (
size_t ,
void * ptr)
329 static void operator delete (
void * ptr)
331 aligned_dealloc<BLOCK_ALIGN>(ptr);
334 static void operator delete[] (
void * ptr)
336 aligned_dealloc<BLOCK_ALIGN>(ptr);
339 static void operator delete (
void *,
void *)
354 STXXL_VERBOSE_TYPED_BLOCK(
"[" << (
void *)
this <<
"] typed_block is destructed");
361 __STXXL_END_NAMESPACE
363 #endif // !STXXL_TYPED_BLOCK_HEADER
bid_type & operator()(int i)
An operator to access bid references.
Definition: typed_block.h:134
InfoType_ info_type
Type of per block information element.
Definition: typed_block.h:164
virtual request_ptr awrite(void *buffer, offset_type pos, size_type bytes, const completion_handler &on_cmpl)=0
Schedules an asynchronous write request to the file.
Default completion handler class.
Definition: completion_handler.h:94
Block containing elements of fixed length.
Definition: typed_block.h:223
size of block in bytes
Definition: typed_block.h:239
T elem[size]
Array of elements of type T.
Definition: typed_block.h:70
number of elements in block
Definition: typed_block.h:240
no meta info, bids or (non-empty) fillers included in the block, allows value_type array addressing a...
Definition: typed_block.h:241
const_iterator cbegin() const
Returns const_iterator pointing to the first element.
Definition: typed_block.h:93
Completion handler class (Loki-style)
Definition: completion_handler.h:63
file * storage
pointer to the file of the block
Definition: bid.h:48
const_iterator begin() const
Returns const_iterator pointing to the first element.
Definition: typed_block.h:87
const_iterator end() const
Returns const_iterator pointing to the end element.
Definition: typed_block.h:105
Contains data elements for stxxl::typed_block , not intended for direct use.
Definition: typed_block.h:53
iterator begin()
Returns iterator pointing to the first element.
Definition: typed_block.h:81
request_ptr read(const bid_type &bid, completion_handler on_cmpl=default_completion_handler())
Reads block from the disk(s) !
Definition: typed_block.h:281
reference operator[](int i)
An operator to access elements in the block.
Definition: typed_block.h:75
stxxl::int64 offset
offset within the file of the block
Definition: bid.h:49
Implemented as reference counting smart pointer.
Definition: request_ptr.h:34
request_ptr write(const bid_type &bid, completion_handler on_cmpl=default_completion_handler())
Writes block to the disk(s) !
Definition: typed_block.h:269
iterator end()
Returns iterator pointing to the end element.
Definition: typed_block.h:99
virtual request_ptr aread(void *buffer, offset_type pos, size_type bytes, const completion_handler &on_cmpl)=0
Schedules an asynchronous read request to the file.
bid_type ref[nbids]
Array of BID references.
Definition: typed_block.h:131
number of elements in the block
Definition: typed_block.h:66
info_type info
Per block information element.
Definition: typed_block.h:167
constants
Definition: typed_block.h:237
Helper to compute the size of the filler , not intended for direct use.
Definition: typed_block.h:205
Contains per block filler for stxxl::typed_block , not intended for direct use.
Definition: typed_block.h:184
Contains per block information for stxxl::typed_block , not intended for direct use.
Definition: typed_block.h:159
Contains BID references for stxxl::typed_block , not intended for direct use.
Definition: typed_block.h:119
const_iterator cend() const
Returns const_iterator pointing to the end element.
Definition: typed_block.h:111