mn_basic_new_allocaor.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 __MINLIB_BASIC_NEW_ALLOCAOR_H__
19 #define __MINLIB_BASIC_NEW_ALLOCAOR_H__
20 
21 #include "../mn_config.hpp"
22 
23 #include "mn_basic_allocator.hpp"
25 
26 namespace mn {
27  namespace memory {
28 
30  public:
33 
34  static void first() noexcept { }
35 
36  static void* allocate(size_t size, size_t alignment) noexcept {
37  MN_UNUSED_VARIABLE(alignment);
38 
39  void* memory = ::operator new(size, std::nothrow);
40 
41  if(memory == nullptr) {
42  auto handler = std::get_new_handler();
43  if(handler) handler();
44  }
45  return memory;
46  }
47 
48  static void deallocate(void* ptr, size_t size, size_t alignment) noexcept {
49  MN_UNUSED_VARIABLE(size);
50  MN_UNUSED_VARIABLE(alignment);
51 
52  ::operator delete(ptr);
53  }
54 
55  static size_t max_node_size() {
56  return size_t(-1);
57  }
58  static size_t get_max_alocator_size() {
59  return __SIZE_MAX__;
60  }
61  };
62 
63  template <class TFilter = basic_allocator_filter>
65  }
66 }
67 
68 
69 
70 #endif // __MINLIB_BASIC_NEW_ALLOCAOR_H__
Definition: mn_basic_allocator.hpp:49
Definition: mn_basic_new_allocaor.hpp:29
std_allocator_tag() allocator_category
Definition: mn_basic_new_allocaor.hpp:31
static size_t max_node_size()
Definition: mn_basic_new_allocaor.hpp:55
static void deallocate(void *ptr, size_t size, size_t alignment) noexcept
Definition: mn_basic_new_allocaor.hpp:48
static void first() noexcept
Definition: mn_basic_new_allocaor.hpp:34
std::false_type is_thread_safe
Definition: mn_basic_new_allocaor.hpp:32
static size_t get_max_alocator_size()
Definition: mn_basic_new_allocaor.hpp:58
static void * allocate(size_t size, size_t alignment) noexcept
Definition: mn_basic_new_allocaor.hpp:36
#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