Loading...
Searching...
No Matches
estimateSize.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_EXEC_VDF_ESTIMATE_SIZE_H
8#define PXR_EXEC_VDF_ESTIMATE_SIZE_H
9
11
12#include "pxr/pxr.h"
13
15
16#include <memory>
17#include <vector>
18
19PXR_NAMESPACE_OPEN_SCOPE
20
53template < typename T >
54inline size_t
56{
57 return sizeof(T);
58}
59
62template < typename T, uint32_t N >
63inline size_t
65{
66 // It would be more accurate the iterate over v and estimate the size of
67 // each element of v, but we are optimizing for performance rather than
68 // accuracy for now.
69 const size_t numExternal = (v.capacity() > N) ? v.capacity() : 0;
70 const size_t elementSize = v.empty()
71 ? sizeof(T) : VdfEstimateSize(v.front());
72 return sizeof(TfSmallVector<T, N>) + numExternal * elementSize;
73}
74
77template < typename T, typename A >
78inline size_t
79VdfEstimateSize(const std::vector<T, A> &v)
80{
81 // It would be more accurate the iterate over v and estimate the size
82 // of each element of v, but we are optimizing for performance rather
83 // than accuracy for now.
84 const size_t elementSize = v.empty()
85 ? sizeof(T) : VdfEstimateSize(v.front());
86 return sizeof(std::vector<T, A>) + v.capacity() * elementSize;
87}
88
91template < typename T >
92inline size_t
93VdfEstimateSize(const std::shared_ptr<T> &p)
94{
95 return sizeof(std::shared_ptr<T>) + (p ? VdfEstimateSize(*p) : 0);
96}
97
98PXR_NAMESPACE_CLOSE_SCOPE
99
100#endif /* PXR_EXEC_VDF_ESTIMATE_SIZE_H */
This is a small-vector class with local storage optimization, the local storage can be specified via ...
Definition: smallVector.h:157
bool empty() const
Returns true if this vector is empty.
Definition: smallVector.h:608
reference front()
Returns the first element in the vector.
Definition: smallVector.h:699
size_type capacity() const
Returns the current capacity of this vector.
Definition: smallVector.h:617
size_t VdfEstimateSize(const T &)
Estimate the memory footprint of instance t of type T.
Definition: estimateSize.h:55