From 8aa251c4a9e2990568eb8df01078299e7dfd896b Mon Sep 17 00:00:00 2001 From: Joseph Schuchart Date: Tue, 19 Nov 2024 15:41:20 -0500 Subject: [PATCH] Buffer: in-place construct data_copy_type in construct callback Signed-off-by: Joseph Schuchart --- ttg/ttg/parsec/buffer.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/ttg/ttg/parsec/buffer.h b/ttg/ttg/parsec/buffer.h index 5c85c0e06..6feaaf8da 100644 --- a/ttg/ttg/parsec/buffer.h +++ b/ttg/ttg/parsec/buffer.h @@ -88,7 +88,12 @@ namespace detail { public: - /* allocation through PARSEC_OBJ_NEW, so no inline constructor */ + /* default construction and move, but not copy */ + data_copy_type() = default; + data_copy_type(const data_copy_type&) = delete; + data_copy_type(data_copy_type&&) = default; + data_copy_type& operator=(const data_copy_type&) = delete; + data_copy_type& operator=(data_copy_type&&) = default; void construct(PtrT ptr, std::size_t size) { m_allocator = allocator_type{}; @@ -117,7 +122,8 @@ namespace detail { */ static void data_copy_construct(data_copy_type* obj) { - /* nothing to do */ + /* placement new */ + new(obj)(data_copy_type); } static void data_copy_destruct(data_copy_type* obj) @@ -229,7 +235,7 @@ struct Buffer { Buffer(std::shared_ptr ptr, std::size_t n, ttg::scope scope = ttg::scope::SyncIn) : m_data(detail::ttg_parsec_data_types, - detail::empty_allocator> + detail::empty_allocator> ::create_data(ptr, n, scope)) , m_count(n) { } @@ -238,7 +244,7 @@ struct Buffer { Buffer(std::unique_ptr ptr, std::size_t n, ttg::scope scope = ttg::scope::SyncIn) : m_data(detail::ttg_parsec_data_types, - detail::empty_allocator> + detail::empty_allocator> ::create_data(ptr, n, scope)) , m_count(n) { }