8#ifndef PXR_BASE_TRACE_DATA_BUFFER_H
9#define PXR_BASE_TRACE_DATA_BUFFER_H
13#include "pxr/base/trace/api.h"
24PXR_NAMESPACE_OPEN_SCOPE
36 constexpr static size_t DefaultAllocSize = 1024;
47 static_assert(std::is_copy_constructible<T>::value,
48 "Must by copy constructible");
49 static_assert(std::is_trivially_destructible<T>::value,
50 "No destructors will be called");
51 return new(_alloc.Allocate(
alignof(T),
sizeof(T))) T(value);
57 const size_t strLen = std::strlen(str) + 1;
58 void* mem = _alloc.Allocate(
alignof(
char), strLen);
59 char* cstr =
reinterpret_cast<char*
>(mem);
60 std::memcpy(cstr, str, strLen);
69 Allocator(
size_t blockSize)
70 : _desiredBlockSize(blockSize) {}
71 Allocator(Allocator&&) =
default;
72 Allocator& operator=(Allocator&&) =
default;
74 Allocator(
const Allocator&) =
delete;
75 Allocator& operator=(
const Allocator&) =
delete;
77 void* Allocate(
const size_t align,
const size_t size) {
78 Byte* alignedNext = AlignPointer(_next, align);
79 Byte* end = alignedNext + size;
80 if (ARCH_UNLIKELY(end > _blockEnd)) {
81 AllocateBlock(align, size);
82 alignedNext = AlignPointer(_next, align);
90 using Byte = std::uint8_t;
92 static Byte* AlignPointer(Byte* ptr,
const size_t align) {
93 const size_t alignMask = align - 1;
94 return reinterpret_cast<Byte*
>(
95 reinterpret_cast<uintptr_t
>(ptr + alignMask) & ~alignMask);
98 TRACE_API
void AllocateBlock(
const size_t align,
const size_t desiredSize);
100 Byte* _blockEnd =
nullptr;
101 Byte* _next =
nullptr;
102 using BlockPtr = std::unique_ptr<Byte[]>;
103 std::deque<BlockPtr> _blocks;
104 size_t _desiredBlockSize;
110PXR_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.