MCPcopy Create free account
hub / github.com/boostorg/compute / buffer_allocator

Class buffer_allocator

include/boost/compute/allocator/buffer_allocator.hpp:27–113  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25/// \see buffer
26template<class T>
27class buffer_allocator
28{
29public:
30 typedef T value_type;
31 typedef detail::device_ptr<T> pointer;
32 typedef const detail::device_ptr<T> const_pointer;
33 typedef std::size_t size_type;
34 typedef std::ptrdiff_t difference_type;
35
36 explicit buffer_allocator(const context &context)
37 : m_context(context),
38 m_mem_flags(buffer::read_write)
39 {
40 }
41
42 buffer_allocator(const buffer_allocator<T> &other)
43 : m_context(other.m_context),
44 m_mem_flags(other.m_mem_flags)
45 {
46 }
47
48 buffer_allocator<T>& operator=(const buffer_allocator<T> &other)
49 {
50 if(this != &other){
51 m_context = other.m_context;
52 m_mem_flags = other.m_mem_flags;
53 }
54
55 return *this;
56 }
57
58 #ifndef BOOST_COMPUTE_NO_RVALUE_REFERENCES
59 buffer_allocator(buffer_allocator<T>&& other) BOOST_NOEXCEPT
60 : m_context(std::move(other.m_context)),
61 m_mem_flags(other.m_mem_flags)
62 {
63 }
64
65 buffer_allocator<T>& operator=(buffer_allocator<T>&& other) BOOST_NOEXCEPT
66 {
67 m_context = std::move(other.m_context);
68 m_mem_flags = other.m_mem_flags;
69
70 return *this;
71 }
72 #endif // BOOST_COMPUTE_NO_RVALUE_REFERENCES
73
74 ~buffer_allocator()
75 {
76 }
77
78 pointer allocate(size_type n)
79 {
80 buffer buf(m_context, n * sizeof(T), m_mem_flags);
81 clRetainMemObject(buf.get());
82 return detail::device_ptr<T>(buf);
83 }
84

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected