alpaka
Abstraction Library for Parallel Kernel Acceleration
AllocCpuNew.hpp
Go to the documentation of this file.
1 /* Copyright 2022 Axel Huebl, Benjamin Worpitz, Bernhard Manfred Gruber
2  * SPDX-License-Identifier: MPL-2.0
3  */
4 
5 #pragma once
6 
7 #include "alpaka/core/Common.hpp"
9 
10 namespace alpaka
11 {
12  //! The CPU new allocator.
13  class AllocCpuNew : public concepts::Implements<ConceptMemAlloc, AllocCpuNew>
14  {
15  };
16 
17  namespace trait
18  {
19  //! The CPU new allocator memory allocation trait specialization.
20  template<typename T>
21  struct Malloc<T, AllocCpuNew>
22  {
23  ALPAKA_FN_HOST static auto malloc(AllocCpuNew const& /* alloc */, std::size_t const& sizeElems) -> T*
24  {
25  return new T[sizeElems];
26  }
27  };
28 
29  //! The CPU new allocator memory free trait specialization.
30  template<typename T>
31  struct Free<T, AllocCpuNew>
32  {
33  ALPAKA_FN_HOST static auto free(AllocCpuNew const& /* alloc */, T const* const ptr) -> void
34  {
35  return delete[] ptr;
36  }
37  };
38  } // namespace trait
39 } // namespace alpaka
The CPU new allocator.
Definition: AllocCpuNew.hpp:14
#define ALPAKA_FN_HOST
Definition: Common.hpp:40
The alpaka accelerator library.
Tag used in class inheritance hierarchies that describes that a specific concept (TConcept) is implem...
Definition: Concepts.hpp:15
static ALPAKA_FN_HOST auto free(AllocCpuNew const &, T const *const ptr) -> void
Definition: AllocCpuNew.hpp:33
The memory free trait.
Definition: Traits.hpp:28
static ALPAKA_FN_HOST auto malloc(AllocCpuNew const &, std::size_t const &sizeElems) -> T *
Definition: AllocCpuNew.hpp:23
The memory allocation trait.
Definition: Traits.hpp:24