Loading...
Searching...
No Matches
zeroAllocator.h
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
18PXR_NAMESPACE_OPEN_SCOPE
19
25template <typename T>
26struct WorkZeroAllocator : public tbb::cache_aligned_allocator<T> {
27 using value_type = T;
28 using propagate_on_container_move_assignment = std::true_type;
29 using is_always_equal = std::true_type;
30
31 template<typename U> struct rebind {
32 typedef WorkZeroAllocator<U> other;
33 };
34
35 WorkZeroAllocator() = default;
36
37 template <typename U>
38 WorkZeroAllocator(const WorkZeroAllocator<U>&) noexcept {};
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
47PXR_NAMESPACE_CLOSE_SCOPE
48
49#endif
An allocator that provides zero-initialized memory.
Definition: zeroAllocator.h:26