From b0520d7a1bffaff1ca7161f5b7672f06b13808a1 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 16 Apr 2023 22:07:10 +0200 Subject: Use a shared_ptr for ArrayData rather than a shared_array. This is simpler and allows us to remove the hack of allocating some "maximum" buffer for incoming JPEG2000 data. It does mean that the buffer is zero-initialized before being written to, but hopefully that doesn't matter too much. --- src/array_data.cc | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) (limited to 'src/array_data.cc') diff --git a/src/array_data.cc b/src/array_data.cc index 1234ba22..52a22cf6 100644 --- a/src/array_data.cc +++ b/src/array_data.cc @@ -45,35 +45,25 @@ #include -using boost::shared_array; using namespace dcp; ArrayData::ArrayData () + : _data(std::make_shared>()) { } ArrayData::ArrayData (int size) - : _data (new uint8_t[size]) - , _size (size) + : _data(std::make_shared>(size)) { } ArrayData::ArrayData (uint8_t const * data, int size) - : _data (new uint8_t[size]) - , _size (size) -{ - memcpy (_data.get(), data, size); -} - - -ArrayData::ArrayData (shared_array data, int size) - : _data (data) - , _size (size) + : _data(std::make_shared>(data, data + size)) { } @@ -81,15 +71,15 @@ ArrayData::ArrayData (shared_array data, int size) ArrayData::ArrayData (boost::filesystem::path file) { - _size = boost::filesystem::file_size (file); - _data.reset (new uint8_t[_size]); + auto const size = boost::filesystem::file_size (file); + _data = std::make_shared>(size); File f(file, "rb"); if (!f) { throw FileError ("could not open file for reading", file, errno); } - if (f.read(_data.get(), 1, _size) != static_cast(_size)) { + if (f.read(_data->data(), 1, size) != static_cast(size)) { throw FileError ("could not read from file", file, errno); } } -- cgit v1.2.3