From 9268279b47e8c2caab81102a75ddee01bcdbdac4 Mon Sep 17 00:00:00 2001 From: Kevin Backhouse Date: Fri, 24 Dec 2021 15:04:14 +0000 Subject: [PATCH] Add comments. --- src/tiffcomposite_int.hpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/tiffcomposite_int.hpp b/src/tiffcomposite_int.hpp index d5a5ebe9..3b48ae9d 100644 --- a/src/tiffcomposite_int.hpp +++ b/src/tiffcomposite_int.hpp @@ -436,7 +436,21 @@ namespace Exiv2 { void encode(TiffEncoder& encoder, const Exifdatum* datum); //! Set the offset void setOffset(int32_t offset) { offset_ = offset; } - //! Set pointer and size of the entry's data (not taking ownership of the data). + /*! + @brief Set pointer and size of the entry's data (not taking ownership of the data). + + @param storage Usually, pData is a pointer into a copy of the image file, which + means that it points to memory which is guaranteed to live longer + than this class. However, sometimes pData is pointer into a + DataBuf that was allocated by another node in the component tree. + If so, we need to make sure that the DataBuf doesn't get freed too + early. We use a std::shared_ptr to hold a reference to the DataBuf + to ensure that it will be kept alive. The storage parameter is + assigned to the storage_ field. In the more common scenario where + pData points to a copy of the image, rather than a DataBuf, then + you should pass std::shared_ptr(), which is essentially + a nullptr. + */ void setData(byte* pData, int32_t size, const std::shared_ptr& storage); /*! @brief Set the entry's data buffer. A shared_ptr is used to manage the DataBuf @@ -533,6 +547,7 @@ namespace Exiv2 { TiffType tiffType, ByteOrder byteOrder); + //! Used (internally) to create another reference to the DataBuf reference by storage_. const std::shared_ptr& storage() { return storage_; } private: