siplasplas
embedded_allocator.hpp
1 #ifndef SIPLASPLAS_ALLOCATOR_DETAIL_EMBEDDED_ALLOCATOR_HPP
2 #define SIPLASPLAS_ALLOCATOR_DETAIL_EMBEDDED_ALLOCATOR_HPP
3 
4 #include <siplasplas/utility/memory_manip.hpp>
5 #include <siplasplas/allocator/export.hpp>
6 #include <string>
7 
8 namespace cpp
9 {
10  class SIPLASPLAS_ALLOCATOR_EXPORT EmbeddedAllocator
11  {
12  public:
13  EmbeddedAllocator(void* begin, void* end, std::size_t metadata_length = 0);
14 
15  char* begin() const;
16  char* end() const;
17  char* metadata_begin() const;
18  char* metadata_end() const;
19 
20  std::size_t storage_size() const;
21  std::size_t metadata_length() const;
22 
23  template<typename T>
24  detail::RawReaderWriter<T> metadata(std::size_t begin)
25  {
26  return{ metadata_begin() + begin };
27  }
28 
29  template<typename T>
30  T metadata(std::size_t begin) const
31  {
32  return detail::read_at<T>(metadata_begin() + begin);
33  }
34 
35  bool belongs_to_storage(void* pointer) const;
36 
37  std::string dump() const;
38 
39  private:
40  char* _begin;
41  };
42 }
43 
44 #endif // SIPLASPLAS_ALLOCATOR_DETAIL_EMBEDDED_ALLOCATOR_HPP
Definition: messaging.hpp:8
constexpr auto end(const Sequence &sequence)
Returns an iterator pointing to the end of a sequence.
Definition: algorithm.hpp:86
constexpr auto begin(const Sequence &sequence)
Returns an iterator pointing to the beginning of a sequence.
Definition: algorithm.hpp:62
Definition: embedded_allocator.hpp:10
Definition: memory_manip.hpp:410