Skip to content

Commit

Permalink
add virtual heapsize() method to ImageInput and ImageOutput
Browse files Browse the repository at this point in the history
Signed-off-by: Basile Fraboni <[email protected]>
  • Loading branch information
bfraboni committed Aug 9, 2024
1 parent dad4ce5 commit d72a0b9
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 6 deletions.
10 changes: 10 additions & 0 deletions src/include/OpenImageIO/imageio.h
Original file line number Diff line number Diff line change
Expand Up @@ -1778,6 +1778,11 @@ class OIIO_API ImageInput {
/// `ImageInput*`.
typedef ImageInput* (*Creator)();

/// Memory tracking method.
/// Return the total heap memory allocated by `ImageOutput`.
/// Overridable version of heapsize defined in memory.h.
virtual size_t heapsize() const;

protected:
ImageSpec m_spec; // format spec of the current open subimage/MIPlevel
// BEWARE using m_spec directly -- not thread-safe
Expand Down Expand Up @@ -2570,6 +2575,11 @@ class OIIO_API ImageOutput {
/// `ImageOutput*`.
typedef ImageOutput* (*Creator)();

/// Memory tracking method.
/// Return the total heap memory allocated by `ImageOutput`.
/// Overridable version of heapsize defined in memory.h.
virtual size_t heapsize() const;

protected:
/// @{
/// @name Helper functions for ImageOutput implementations.
Expand Down
23 changes: 20 additions & 3 deletions src/libOpenImageIO/imageinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1339,13 +1339,30 @@ ImageInput::check_open(const ImageSpec& spec, ROI range, uint64_t /*flags*/)



template <>
inline size_t
pvt::heapsize<ImageInput::Impl>(const ImageInput::Impl& impl)
{
return impl.m_io_local ? sizeof(Filesystem::IOProxy) : 0;
}



size_t
ImageInput::heapsize() const
{
size_t size = pvt::heapsize(m_impl);
size += pvt::heapsize(m_spec);
return size;
}



template<>
size_t
pvt::heapsize<ImageInput>(const ImageInput& input)
{
//! TODO: change ImageInput API to add a virtual heapsize() function
//! to allow per image input override, and call that function here.
return pvt::heapsize(input.m_spec);
return input.heapsize();
}


Expand Down
23 changes: 20 additions & 3 deletions src/libOpenImageIO/imageoutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1021,13 +1021,30 @@ ImageOutput::check_open(OpenMode mode, const ImageSpec& userspec, ROI range,



template <>
inline size_t
pvt::heapsize<ImageOutput::Impl>(const ImageOutput::Impl& impl)
{
return impl.m_io_local ? sizeof(Filesystem::IOProxy) : 0;
}



size_t
ImageOutput::heapsize() const
{
size_t size = pvt::heapsize(m_impl);
size += pvt::heapsize(m_spec);
return size;
}



template<>
size_t
pvt::heapsize<ImageOutput>(const ImageOutput& output)
{
//! TODO: change ImageOutput API to add a virtual heapsize() function
//! to allow per image output override, and call that function here.
return pvt::heapsize(output.m_spec);
return output.heapsize();
}


Expand Down

0 comments on commit d72a0b9

Please sign in to comment.