25#ifndef PXR_BASE_TRACE_DATA_BUFFER_H
26#define PXR_BASE_TRACE_DATA_BUFFER_H
30#include "pxr/base/trace/api.h"
41PXR_NAMESPACE_OPEN_SCOPE
53 constexpr static size_t DefaultAllocSize = 1024;
64 static_assert(std::is_copy_constructible<T>::value,
65 "Must by copy constructible");
66 static_assert(std::is_trivially_destructible<T>::value,
67 "No destructors will be called");
68 return new(_alloc.Allocate(
alignof(T),
sizeof(T))) T(value);
74 const size_t strLen = std::strlen(str) + 1;
75 void* mem = _alloc.Allocate(
alignof(
char), strLen);
76 char* cstr =
reinterpret_cast<char*
>(mem);
77 std::memcpy(cstr, str, strLen);
86 Allocator(
size_t blockSize)
87 : _desiredBlockSize(blockSize) {}
88 Allocator(Allocator&&) =
default;
89 Allocator& operator=(Allocator&&) =
default;
91 Allocator(
const Allocator&) =
delete;
92 Allocator& operator=(
const Allocator&) =
delete;
94 void* Allocate(
const size_t align,
const size_t size) {
95 Byte* alignedNext = AlignPointer(_next, align);
96 Byte* end = alignedNext + size;
97 if (ARCH_UNLIKELY(end > _blockEnd)) {
98 AllocateBlock(align, size);
99 alignedNext = AlignPointer(_next, align);
107 using Byte = std::uint8_t;
109 static Byte* AlignPointer(Byte* ptr,
const size_t align) {
110 const size_t alignMask = align - 1;
111 return reinterpret_cast<Byte*
>(
112 reinterpret_cast<uintptr_t
>(ptr + alignMask) & ~alignMask);
115 TRACE_API
void AllocateBlock(
const size_t align,
const size_t desiredSize);
117 Byte* _blockEnd =
nullptr;
118 Byte* _next =
nullptr;
119 using BlockPtr = std::unique_ptr<Byte[]>;
120 std::deque<BlockPtr> _blocks;
121 size_t _desiredBlockSize;
127PXR_NAMESPACE_CLOSE_SCOPE
This class stores copies of data that are associated with TraceEvent instances.
TraceDataBuffer(size_t allocSize=DefaultAllocSize)
Constructor.
const T * StoreData(const T &value)
Makes a copy of value and returns a pointer to it.
const char * StoreData(const char *str)
Makes a copy of str and returns a pointer to it.