18 #ifndef FOXXLL_MNG_TYPED_BLOCK_HEADER 19 #define FOXXLL_MNG_TYPED_BLOCK_HEADER 22 #include <foxxll/config.hpp> 28 #ifdef FOXXLL_VERBOSE_TYPED_BLOCK 31 constexpr
bool debug_typed_block =
false;
45 template <
size_t Bytes>
55 <<
"[" <<
static_cast<void*
>(
this) <<
"] filler_struct is constructed";
68 <<
"[" <<
static_cast<void*
>(
this) <<
"] filler_struct<> is constructed";
73 template <
typename Type,
size_t kSize>
85 static constexpr
size_t size = kSize;
93 <<
"[" <<
static_cast<void*
>(
this) <<
"] element_block is constructed";
140 template <
typename Type,
size_t Size,
size_t RawSize,
size_t NB
ids = 0>
144 static constexpr
size_t raw_size = RawSize;
145 static constexpr
size_t kNBIDs = NBids;
161 <<
"[" <<
static_cast<void*
>(
this) <<
"] block_w_bids is constructed";
165 template <
typename Type,
size_t Size,
size_t RawSize>
170 static constexpr
size_t raw_size = RawSize;
171 static constexpr
size_t kNBIDs = 0;
178 <<
"[" <<
static_cast<void*
>(
this) <<
"] block_w_bids<> is constructed";
183 template <
typename Type,
size_t RawSize,
size_t NB
ids,
typename MetaInfoType =
void>
185 :
public block_w_bids<Type, ((RawSize - sizeof(BID<RawSize>)* NBids - sizeof(MetaInfoType)) / sizeof(Type)), RawSize, NBids>
197 <<
"[" <<
static_cast<void*
>(
this) <<
"] block_w_info is constructed";
201 template <
typename Type,
size_t RawSize,
size_t NB
ids>
203 :
public block_w_bids<Type, ((RawSize - sizeof(BID<RawSize>)* NBids) / sizeof(Type)), RawSize, NBids>
211 <<
"[" <<
static_cast<void*
>(
this) <<
"] block_w_info<> is constructed";
216 template <
typename BaseType,
size_t FillSize = 0>
227 <<
"[" <<
static_cast<void*
>(
this) <<
"] add_filler is constructed";
231 template <
typename BaseType>
239 <<
"[" <<
static_cast<void*
>(
this) <<
"] add_filler<> is constructed";
244 template <
typename Type,
size_t RawSize>
265 template <
size_t RawSize,
typename Type,
size_t NRef = 0,
typename MetaInfoType =
void>
271 constexpr
static bool debug_block_life_cycle =
false;
282 static constexpr
size_t raw_size = RawSize;
283 static constexpr
size_t size = Base::size;
284 static constexpr
bool has_only_data = (raw_size == (size *
sizeof(
value_type)));
292 "sizeof(typed_block) == raw_size" 295 <<
"[" <<
static_cast<void*
>(
this) <<
"] typed_block is constructed";
311 <<
"BLC:write " << bid;
325 <<
"BLC:read " << bid;
339 <<
"BLC:write " << bid;
340 assert(bid.
size >= raw_size);
354 <<
"BLC:read " << bid;
355 assert(bid.
size >= raw_size);
359 static void*
operator new (
size_t bytes)
361 size_t meta_info_size =
bytes % raw_size;
363 <<
"typed::block operator new[]: bytes=" <<
bytes 364 <<
", meta_info_size=" << meta_info_size;
366 void* result = aligned_alloc<BlockAlignment>(
367 bytes - meta_info_size, meta_info_size
370 #if FOXXLL_WITH_VALGRIND 371 memset(result, 0,
bytes);
376 static void*
operator new[] (
size_t bytes)
378 size_t meta_info_size =
bytes % raw_size;
380 <<
"typed::block operator new[]: bytes=" <<
bytes 381 <<
", meta_info_size=" << meta_info_size;
383 void* result = aligned_alloc<BlockAlignment>(
384 bytes - meta_info_size, meta_info_size
387 #if FOXXLL_WITH_VALGRIND 388 memset(result, 0,
bytes);
393 static void*
operator new (
size_t ,
void* ptr)
398 static void operator delete (
void* ptr)
400 aligned_dealloc<BlockAlignment>(ptr);
403 static void operator delete[] (
void* ptr)
405 aligned_dealloc<BlockAlignment>(ptr);
408 static void operator delete (
void*,
void*)
424 <<
"[" <<
static_cast<void*
>(
this) <<
"] typed_block is destructed";
433 #endif // !FOXXLL_MNG_TYPED_BLOCK_HEADER
external_size_type offset
offset within the file of the block (uint64_t)
Helper to compute the size of the filler , not intended for direct use.
byte_type filler_array[Bytes]
const value_type * const_pointer
iterator end()
Returns iterator pointing to the end element.
Specialization of block identifier class (BID) for variable size block size.
virtual request_ptr awrite(void *buffer, offset_type pos, size_type bytes, const completion_handler &on_complete=completion_handler())=0
external_size_type offset
offset within the file of the block (uint64_t)
const_pointer const_iterator
MetaInfoType info_type
Type of per block information element.
iterator begin()
Returns iterator pointing to the first element.
virtual request_ptr aread(void *buffer, offset_type pos, size_type bytes, const completion_handler &on_complete=completion_handler())=0
const_iterator end() const
Returns const_iterator pointing to the end element.
constexpr bool debug_typed_block
constexpr size_t BlockAlignment
tlx::delegate< void(request *r, bool success)> completion_handler
completion handler
Contains per block information for foxxll::typed_block , not intended for direct use.
const_iterator begin() const
Returns const_iterator pointing to the first element.
const_iterator cbegin() const
Returns const_iterator pointing to the first element.
request_ptr read(const BID< 0 > &bid, completion_handler on_complete=completion_handler())
Reads block from the disk(s).
Contains per block filler for foxxll::typed_block , not intended for direct use.
#define TLX_LOGC(cond)
Explicitly specify the condition for logging.
file * storage
pointer to the file of the block
High-performance smart pointer used as a wrapping reference counting pointer.
const Type & const_reference
static const size_t bytes
number of bytes in uint_pair
Contains BID references for foxxll::typed_block , not intended for direct use.
const value_type & const_reference
request_ptr write(const BID< 0 > &bid, completion_handler on_complete=completion_handler())
Writes block to the disk(s).
filler_struct< FillSize > filler
Per block filler element.
request_ptr write(const bid_type &bid, completion_handler on_complete=completion_handler())
Writes block to the disk(s).
size_t size
size of the block in bytes
file * storage
pointer to the file of the block
Contains data elements for foxxll::typed_block , not intended for direct use.
request_ptr read(const bid_type &bid, completion_handler on_complete=completion_handler())
Reads block from the disk(s).
info_type info
Per block information element.
const type * const_iterator
const_iterator cend() const
Returns const_iterator pointing to the end element.