diff --git a/hamr_buffer.h b/hamr_buffer.h index 09ae4d4..16b8a1c 100644 --- a/hamr_buffer.h +++ b/hamr_buffer.h @@ -279,9 +279,11 @@ class HAMR_EXPORT buffer * driver API is used to determine the device that * allocated the memory. * @param[in] ptr a pointer to the array + * @param[in] take set non-zero if the buffer should delete the passed + * memory using the named allocator */ buffer(allocator alloc, const hamr::stream &strm, - transfer sync, size_t size, int owner, T *ptr); + transfer sync, size_t size, int owner, T *ptr, int take = 1); /** Construct by directly providing the buffer contents. This can be used * for zero-copy transfer of data. One must also name the allocator type diff --git a/hamr_buffer_impl.h b/hamr_buffer_impl.h index 81a5395..00b83a4 100644 --- a/hamr_buffer_impl.h +++ b/hamr_buffer_impl.h @@ -242,14 +242,18 @@ buffer::buffer(allocator alloc, const hamr::stream &strm, transfer sync, // -------------------------------------------------------------------------- template buffer::buffer(allocator alloc, const hamr::stream &strm, transfer sync, - size_t size, int owner, T *ptr) : m_alloc(alloc), m_data(nullptr), + size_t size, int owner, T *ptr, int take) : m_alloc(alloc), m_data(nullptr), m_size(size), m_capacity(size), m_owner(owner), m_stream(strm), m_sync(sync) { assert_valid_allocator(alloc); // create the deleter for the passed allocator - if (alloc == allocator::cpp) + if (!take) + { + m_data = std::shared_ptr(ptr, [](T*){}); + } + else if (alloc == allocator::cpp) { m_data = std::shared_ptr(ptr, new_deleter(ptr, m_size)); }