diff options
| author | Carl Hetherington <cth@carlh.net> | 2023-04-16 22:07:10 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2023-04-16 22:14:26 +0200 |
| commit | b0520d7a1bffaff1ca7161f5b7672f06b13808a1 (patch) | |
| tree | 8b7777c6fc7fc6f2f36e85c60151031b8860a09b /src/array_data.cc | |
| parent | 65d21ed2de3a76dc574c8ad111fc02d8f696fcd6 (diff) | |
Use a shared_ptr<vector> 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.
Diffstat (limited to 'src/array_data.cc')
| -rw-r--r-- | src/array_data.cc | 22 |
1 files changed, 6 insertions, 16 deletions
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 <cstdio> -using boost::shared_array; using namespace dcp; ArrayData::ArrayData () + : _data(std::make_shared<std::vector<uint8_t>>()) { } ArrayData::ArrayData (int size) - : _data (new uint8_t[size]) - , _size (size) + : _data(std::make_shared<std::vector<uint8_t>>(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<uint8_t> data, int size) - : _data (data) - , _size (size) + : _data(std::make_shared<std::vector<uint8_t>>(data, data + size)) { } @@ -81,15 +71,15 @@ ArrayData::ArrayData (shared_array<uint8_t> 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<std::vector<uint8_t>>(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_t>(_size)) { + if (f.read(_data->data(), 1, size) != static_cast<size_t>(size)) { throw FileError ("could not read from file", file, errno); } } |
