/* * File: allocator_op.hpp * Purpose: Allocate from a pool. * Author: Amlal El Mahrouss (amlal@nekernel.org) * Copyright 2025, Amlal El Mahrouss, Licensed under the Boost Software License. Licensed under the BSL 1.0 license */ #ifndef __OCL_CORE_ALLOC #define __OCL_CORE_ALLOC #include #include namespace ocl { /// @note these are guidelines on allocating a resource template struct global_new_op final { using pointer_type = type*; auto alloc() -> pointer_type { return new type; } template auto array_alloc() -> pointer_type { return new type[N]; } template auto var_alloc(var_type&&... args) -> pointer_type { return new type{std::forward(args)...}; } }; template struct global_array_delete_op final { using pointer_type = type*; auto operator()(pointer_type t) -> void { delete[] t; } }; template class allocator_op { public: allocator_op() = default; ~allocator_op() = default; allocator_op& operator=(const allocator_op&) = delete; allocator_op(const allocator_op&) = delete; template auto construct_var(var_type... args) { return std::shared_ptr(allocator_new{}.template var_alloc(std::forward(args)...), allocator_delete{}); } template auto construct_array() { return std::shared_ptr(allocator_new{}.template array_alloc(), allocator_delete{}); } }; template using allocator = allocator_op, global_array_delete_op>; } // namespace ocl #endif // ifndef __OCL_CORE_ALLOC