MeshLib
 
Loading...
Searching...
No Matches
MRHeapBytes.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRMeshFwd.h"
4#include <vector>
5#include <memory>
6
7namespace MR
8{
9
12
14template<typename T>
15[[nodiscard]] inline size_t heapBytes( const std::vector<T> & vec )
16{
17 constexpr bool hasHeapBytes = requires( const T& t ) { t.heapBytes(); };
18 if constexpr ( hasHeapBytes )
19 {
20 size_t res = vec.capacity() * sizeof( T );
21 for ( const T & t : vec )
22 res += t.heapBytes();
23 return res;
24 }
25 else
26 {
27 return vec.capacity() * sizeof( T );
28 }
29}
30
31template<typename T, typename U>
32[[nodiscard]] inline size_t heapBytes( const Vector<T, U>& vec )
33{
34 constexpr bool hasHeapBytes = requires( const T & t ) { t.heapBytes(); };
35 if constexpr ( hasHeapBytes )
36 {
37 size_t res = vec.size() * sizeof( T );
38 for ( const T & t : vec )
39 res += t.heapBytes();
40 return res;
41 }
42 else
43 {
44 return vec.size() * sizeof( T );
45 }
46}
47
49template<typename T>
50[[nodiscard]] inline size_t heapBytes( const std::unique_ptr<T> & ptr )
51{
52 if ( !ptr )
53 return 0;
54 return sizeof( T ) + ptr->heapBytes();
55}
56
58template<typename T>
59[[nodiscard]] inline size_t heapBytes( const std::shared_ptr<T> & ptr )
60{
61 if ( !ptr )
62 return 0;
63 return sizeof( T ) + ptr->heapBytes();
64}
65
67template<typename T>
68[[nodiscard]] inline size_t heapBytes( const std::function<T> & )
69{
70 return 0;
71}
72
74
75} // namespace MR
std::vector<T>-like container that requires specific indexing type,
Definition MRMesh/MRVector.h:19
std::size_t size() const
Definition MRMesh/MRVector.h:40
MRMESH_API size_t heapBytes(const FloatGrid &grid)
returns the amount of heap memory occupied by grid
Definition MRCameraOrientationPlugin.h:7