1 #ifndef OMEGA_H_MEMORY_HPP
2 #define OMEGA_H_MEMORY_HPP
13 template <
typename... Args>
15 #if defined(OMEGA_H_COMPILING_FOR_HOST)
16 : ptr_(
new T(std::forward<Args>(args)...)) {
17 [[maybe_unused]]
auto [itr, inserted] = refCount_.insert(std::make_pair(ptr_, 1));
26 #if defined(OMEGA_H_COMPILING_FOR_HOST)
37 auto itr = refCount_.find(ptr_);
38 assert(itr != refCount_.end());
44 #if defined(OMEGA_H_COMPILING_FOR_HOST)
55 auto itr = refCount_.find(ptr_);
56 assert(itr != refCount_.end());
62 #if defined(OMEGA_H_COMPILING_FOR_HOST)
73 auto itr = refCount_.find(ptr_);
74 assert(itr != refCount_.end());
82 #if defined(OMEGA_H_COMPILING_FOR_HOST)
93 auto itr = refCount_.find(ptr_);
94 assert(itr != refCount_.end());
101 OMEGA_H_INLINE T* get()
const {
102 #if defined(OMEGA_H_COMPILING_FOR_HOST)
109 OMEGA_H_INLINE T* operator->()
const {
110 #if defined(OMEGA_H_COMPILING_FOR_HOST)
117 OMEGA_H_INLINE T& operator*()
const {
118 #if defined(OMEGA_H_COMPILING_FOR_HOST)
126 #if defined(OMEGA_H_COMPILING_FOR_HOST)
133 OMEGA_H_INLINE
explicit operator bool()
const {
134 #if defined(OMEGA_H_COMPILING_FOR_HOST)
135 return ptr_ !=
nullptr && (refCount_.find(ptr_) != refCount_.end());
141 OMEGA_H_INLINE
int use_count()
const {
142 #if defined(OMEGA_H_COMPILING_FOR_HOST)
143 return *
this ? refCount_.find(ptr_)->second : 0;
150 void decrementRefCount() {
151 #if defined(OMEGA_H_COMPILING_FOR_HOST)
156 auto itr = refCount_.find(ptr_);
157 assert(itr != refCount_.end());
159 if (itr->second == 0) {
160 refCount_.erase(itr);
168 static std::map<T*, int> refCount_;
171 template <
typename T>
Definition: Omega_h_memory.hpp:9
Definition: amr_mpi_test.cpp:6