Atlas Runtime
atlas_alloc_cpp.hpp
Go to the documentation of this file.
1 /*
2  * (c) Copyright 2016 Hewlett Packard Enterprise Development LP
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as
6  * published by the Free Software Foundation, either version 3 of the
7  * License, or (at your option) any later version. This program is
8  * distributed in the hope that it will be useful, but WITHOUT ANY
9  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11  * for more details. You should have received a copy of the GNU Lesser
12  * General Public License along with this program. If not, see
13  * <http://www.gnu.org/licenses/>.
14  */
15 
16 
17 #ifndef ATLAS_ALLOC_CPP_H
18 #define ATLAS_ALLOC_CPP_H
19 
20 // Forward declarations
21 namespace Atlas
22 {
23  class PRegion;
24 }
25 
34 Atlas::PRegion *NVM_GetRegion(uint32_t rid);
35 
45 void* operator new(size_t sz, Atlas::PRegion *rgn) noexcept;
46 
59 void* operator new[](size_t sz, Atlas::PRegion *rgn) noexcept;
60 
77 template <class T> static inline void NVM_Destroy(T *ptr)
78 {
79  if (!ptr) return;
80  if (!NVM_IsInRegion(ptr, 1 /* dummy, since size unknown */)) {
81  delete ptr;
82  return;
83  }
84  ptr->~T();
85  void nvm_delete(void*);
86  nvm_delete(ptr);
87 }
88 
106 template <class T> static inline void NVM_Destroy_Array(T *ptr)
107 {
108  if (!ptr) return;
109  if (!NVM_IsInRegion(ptr, 1 /* dummy, since size unknown */)) {
110  delete [] ptr;
111  return;
112  }
113  char *delete_ptr = reinterpret_cast<char*>(ptr) - sizeof(size_t);
114  size_t count = *reinterpret_cast<size_t*>(delete_ptr);
115  for (int i=count-1; i>=0; --i) (ptr+i)->~T();
116  void nvm_delete(void*);
117  nvm_delete(delete_ptr);
118 }
119 
120 #endif
Definition: pregion.hpp:31
int NVM_IsInRegion(void *ptr, size_t sz)
Determines if a memory location is within a region.
Definition: pregion_mgr_api.cpp:111
Atlas::PRegion * NVM_GetRegion(uint32_t rid)
Get a handle to a persistent region.
Definition: pregion_mgr_api.cpp:116
Definition: atlas_alloc_cpp.hpp:21
void nvm_delete(void *ptr)
Definition: pregion_mgr_api.cpp:83