Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

debug_size_heap.hpp
Go to the documentation of this file.
1 //
2 // immer: immutable data structures for C++
3 // Copyright (C) 2016, 2017, 2018 Juan Pedro Bolivar Puente
4 //
5 // This software is distributed under the Boost Software License, Version 1.0.
6 // See accompanying file LICENSE or copy at http://boost.org/LICENSE_1_0.txt
7 //
8 
9 #pragma once
10 
11 #include <cassert>
12 #include <cstddef>
13 #include <immer/config.hpp>
15 
16 namespace immer {
17 
18 #if IMMER_ENABLE_DEBUG_SIZE_HEAP
19 
24 template <typename Base>
25 struct debug_size_heap
26 {
27  // temporary fix until https://github.com/arximboldi/immer/issues/78 is fixed
28  constexpr static auto extra_size = sizeof(void*) * 2; //alignof(std::max_align_t);
29 
30  template <typename... Tags>
31  static void* allocate(std::size_t size, Tags... tags)
32  {
33  auto p = (std::size_t*) Base::allocate(size + extra_size, tags...);
34  *p = size;
35  return ((char*)p) + extra_size;
36  }
37 
38  template <typename... Tags>
39  static void deallocate(std::size_t size, void* data, Tags... tags)
40  {
41  auto p = (std::size_t*) (((char*) data) - extra_size);
42  assert(*p == size);
43  Base::deallocate(size + extra_size, p, tags...);
44  }
45 };
46 
47 #else // IMMER_ENABLE_DEBUG_SIZE_HEAP
48 
49 template <typename Base>
51 
52 #endif // !IMMER_ENABLE_DEBUG_SIZE_HEAP
53 
54 } // namespace immer
std::size_t size_t
Definition: bits.hpp:21
static void deallocate(std::size_t size, void *data, Tags... tags)
static void * allocate(std::size_t size, Tags... tags)
identity_heap< Base > debug_size_heap
Released under the MIT license