-
Notifications
You must be signed in to change notification settings - Fork 606
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add datasize() and footprint() methods to ParamValue, ParamValueList,…
… and ImageSpec Signed-off-by: Basile Fraboni <[email protected]>
- Loading branch information
Showing
5 changed files
with
155 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright 2008-present Contributors to the OpenImageIO project. | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
// https://github.com/OpenImageIO/oiio | ||
|
||
|
||
///////////////////////////////////////////////////////////////////////////// | ||
/// \file | ||
/// | ||
/// Provides helper function to compute the memory footprint of common | ||
/// containers. | ||
/// | ||
///////////////////////////////////////////////////////////////////////////// | ||
|
||
#pragma once | ||
|
||
#define OPENIMAGEIO_MEMORY_H | ||
|
||
OIIO_NAMESPACE_BEGIN | ||
|
||
/// Return the total heap allocated memory used by the container. | ||
/// Variant for primitive types or trivial structures. | ||
template<class VecType> | ||
inline size_t | ||
vector_bytes(const VecType& v) | ||
{ | ||
using T = typename VecType::value_type; | ||
return v.capacity() * sizeof(T); | ||
} | ||
|
||
/// Return the total heap allocated memory used by the container. | ||
/// Variant for strings, including the reserved string entries, | ||
/// and each string capacity. | ||
template<class VecType> | ||
inline size_t | ||
vector_string_datasize(const VecType& v) | ||
{ | ||
using T = typename VecType::value_type; | ||
// account for the size of elements | ||
size_t size = vector_bytes(v); | ||
// account for the size of allocated data | ||
for (const T& ref : v) | ||
size += ref.capacity(); | ||
return size; | ||
} | ||
|
||
/// Return the total heap allocated memory used by the container. | ||
/// Variant for objects implementing the datasize() function, | ||
/// including the reserved object entries, and each object own | ||
/// allocations. | ||
template<class VecType> | ||
inline size_t | ||
vector_datasize(const VecType& v) | ||
{ | ||
using T = typename VecType::value_type; | ||
// account for the size of elements | ||
size_t size = vector_bytes(v); | ||
// account for the size of allocated data | ||
for (const T& ref : v) | ||
size += ref.datasize(); | ||
return size; | ||
} | ||
|
||
/// Return the total heap allocated memory used by the container. | ||
/// Variant for pointers to object implementing the footprint() function, | ||
/// including the reserved pointer entries, and each object footprint. | ||
template<class VecType> | ||
inline size_t | ||
vector_ptr_datasize(const VecType& v) | ||
{ | ||
using T = typename VecType::value_type; | ||
// account for the size of ptrs | ||
size_t size = vector_bytes(v); | ||
// account for the size of allocated objects | ||
for (const T& ptr : v) | ||
size += ptr->footprint(); | ||
return size; | ||
} | ||
|
||
|
||
OIIO_NAMESPACE_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters