mn_basic_multiheap_allocator.hpp
Go to the documentation of this file.
1 /*
2 *This file is part of the Mini Thread Library (https://github.com/RoseLeBlood/MiniThread ).
3 *Copyright (c) 2018 Amber-Sophia Schroeck
4 *
5 *The Mini Thread Library is free software; you can redistribute it and/or modify
6 *it under the terms of the GNU Lesser General Public License as published by
7 *the Free Software Foundation, version 3, or (at your option) any later version.
8 
9 *The Mini Thread Library is distributed in the hope that it will be useful, but
10 *WITHOUT ANY WARRANTY; without even the implied warranty of
11 *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 *General Public License for more details.
13 *
14 *You should have received a copy of the GNU Lesser General Public
15 *License along with the Mini Thread Library; if not, see
16 *<https://www.gnu.org/licenses/>.
17 */
18 #ifndef __MINILIB_BASIC_MULTIHEAP_ALLOCATOR_H__
19 #define __MINILIB_BASIC_MULTIHEAP_ALLOCATOR_H__
20 
21 #include "../mn_config.hpp"
22 
23 #if MN_THREAD_CONFIG_BOARD == MN_THREAD_CONFIG_ESP32
24 
25 #include "mn_basic_allocator.hpp"
27 
28 #include "multi_heap.h"
29 
30 namespace mn {
31  namespace memory {
32 
33  template<size_t TBytes>
35  public:
38 
39 
40  static void first() noexcept {
41  if(m_pHandle != nullptr) return;
42  m_pHandle = multi_heap_register(m_buffer, TBytes);
43  }
44  static void* allocate(size_t size, size_t alignment) noexcept {
45  MN_UNUSED_VARIABLE(alignment);
46  return (void*) multi_heap_malloc(m_pHandle, size );
47  }
48 
49  static void deallocate(void* ptr, size_t size, size_t alignment) noexcept {
50  MN_UNUSED_VARIABLE(size);
51  MN_UNUSED_VARIABLE(alignment);
52 
53  multi_heap_free(m_pHandle, ptr);
54  }
55 
56  static size_t max_node_size() noexcept {
57  return size_t(-1);
58  }
59  static size_t get_max_alocator_size() const noexcept {
60  return TBytes;
61  }
62  private:
63  static char m_buffer[TBytes];
64  static multi_heap_handle_t m_pHandle;
65  };
66 
67  template<size_t TBytes>
69 
70  template<size_t TBytes>
71  multi_heap_handle_t basic_multiheap_allocator_impl<TBytes>::m_pHandle = nullptr;
72 
73 
74  template<size_t TBytes, class TFilter = basic_allocator_filter>
76 
77 
78 
79  }
80 }
81 
82 #endif // MN_THREAD_CONFIG_BOARD
83 
84 
85 #endif // __MINILIB_BASIC_MULTIHEAP_ALLOCATOR_H__
Definition: mn_basic_allocator.hpp:49
Definition: mn_basic_multiheap_allocator.hpp:34
static char m_buffer[TBytes]
Definition: mn_basic_multiheap_allocator.hpp:63
static size_t get_max_alocator_size() const noexcept
Definition: mn_basic_multiheap_allocator.hpp:59
static size_t max_node_size() noexcept
Definition: mn_basic_multiheap_allocator.hpp:56
static void deallocate(void *ptr, size_t size, size_t alignment) noexcept
Definition: mn_basic_multiheap_allocator.hpp:49
static void * allocate(size_t size, size_t alignment) noexcept
Definition: mn_basic_multiheap_allocator.hpp:44
std_allocator_tag() allocator_category
Definition: mn_basic_multiheap_allocator.hpp:36
static void first() noexcept
Definition: mn_basic_multiheap_allocator.hpp:40
std::false_type is_thread_safe
Definition: mn_basic_multiheap_allocator.hpp:37
static multi_heap_handle_t m_pHandle
Definition: mn_basic_multiheap_allocator.hpp:64
#define MN_UNUSED_VARIABLE(var)
Definition: mn_defines.hpp:40
Definition: mn_allocator_typetraits.hpp:27
Definition: mn_allocator_typetraits.hpp:25
MN_THREAD_CONFIG_SIZE_TYPE size_t
Definition: mn_def.hpp:48
integral_constant< bool, false > false_type
Definition: mn_typetraits.hpp:130