HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
zeroAllocator.h
Go to the documentation of this file.
1 //
2 // Copyright 2025 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_BASE_WORK_ZERO_ALLOCATOR_H
8 #define PXR_BASE_WORK_ZERO_ALLOCATOR_H
9 
10 #include "pxr/pxr.h"
11 
12 #include <cstring>
13 #include <type_traits>
14 #include <memory>
15 
16 #include <tbb/cache_aligned_allocator.h>
17 
19 
20 /// An allocator that provides zero-initialized memory.
21 ///
22 /// \note This meets the standard C++ Allocator requirements and can be passed
23 /// as an allocation routine to be used by STL templates.
24 ///
25 template <typename T>
26 struct WorkZeroAllocator : public tbb::cache_aligned_allocator<T> {
27  using value_type = T;
29  using is_always_equal = std::true_type;
30 
31  template<typename U> struct rebind {
33  };
34 
35  WorkZeroAllocator() = default;
36 
37  template <typename U>
39 
40  T* allocate(std::size_t n) {
41  T* ptr = tbb::cache_aligned_allocator<T>::allocate(n);
42  std::memset(static_cast<void*>(ptr), 0, n * sizeof(value_type));
43  return ptr;
44  }
45 };
46 
48 
49 #endif
WorkZeroAllocator(const WorkZeroAllocator< U > &) noexcept
Definition: zeroAllocator.h:38
WorkZeroAllocator< U > other
Definition: zeroAllocator.h:32
T * allocate(std::size_t n)
Definition: zeroAllocator.h:40
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
WorkZeroAllocator()=default
GLdouble n
Definition: glcorearb.h:2008
std::true_type propagate_on_container_move_assignment
Definition: zeroAllocator.h:28
auto ptr(T p) -> const void *
Definition: format.h:4331
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
std::true_type is_always_equal
Definition: zeroAllocator.h:29