HAMR
The Heterogeneous Accelerator Memory Resource
hamr_new_allocator.h
1
#ifndef hamr_new_allocator_h
2
#define hamr_new_allocator_h
3
4
#include "hamr_config.h"
5
#include <type_traits>
6
#include <memory>
7
8
namespace
hamr
9
{
10
11
/// a deleter for arrays allocated with new
12
template
<
typename
T>
13
class
HAMR_EXPORT
new_deleter
14
{
15
public
:
16
/** constructs the deleter
17
* @param[in] ptr the pointer to the array to delete
18
* @param[in] n the number of elements in the array
19
*/
20
new_deleter
(T *ptr,
size_t
n);
21
22
/** deletes the array
23
* @param[in] ptr the pointer to the array to delete. must be the same as
24
* that passed during construction.
25
*/
26
void
operator()(T *ptr);
27
28
private
:
29
T *m_ptr;
30
size_t
m_elem;
31
};
32
33
34
35
36
37
38
/// a class for allocating arrays with new
39
template
<
typename
T>
40
struct
HAMR_EXPORT
new_allocator
41
{
42
/** allocate an array of n elements.
43
* @param[in] n the number of elements to allocate
44
* @returns a shared pointer to the array that holds a deleter for the memory
45
*/
46
static
std::shared_ptr<T> allocate(
size_t
n) HAMR_EXPORT;
47
48
/** allocate an array of n elements.
49
* @param[in] n the number of elements to allocate
50
* @param[in] val a value to initialize the elements to
51
* @returns a shared pointer to the array that holds a deleter for the memory
52
*/
53
static
std::shared_ptr<T> allocate(
size_t
n,
const
T &val) HAMR_EXPORT;
54
55
/** allocate an array of n elements.
56
* @param[in] n the number of elements to allocate
57
* @param[in] vals an array of n values to initialize the elements with
58
* @returns a shared pointer to the array that holds a deleter for the memory
59
*/
60
template
<
typename
U>
61
static
std::shared_ptr<T> allocate(
size_t
n,
const
U *vals) HAMR_EXPORT;
62
};
63
64
}
65
66
#if !defined(HAMR_SEPARATE_IMPL)
67
#include "hamr_new_allocator_impl.h"
68
#endif
69
70
#endif
hamr::new_deleter
a deleter for arrays allocated with new
Definition:
hamr_new_allocator.h:13
hamr
heterogeneous accelerator memory resource
Definition:
hamr_buffer.h:13
hamr::new_allocator
a class for allocating arrays with new
Definition:
hamr_new_allocator.h:40
stable
hamr_new_allocator.h
Generated on Sat Sep 30 2023 04:32:06 for HAMR by
1.8.17