lock_guard<recursive_mutex> lock(_mutex);
- _data = realloc(_data, (_sample_count + sample_count) * sizeof(float));
+ _data.resize((_sample_count + sample_count) * sizeof(float));
- float *dst = (float*)_data + _sample_count;
+ float *dst = (float*)_data.data() + _sample_count;
const float *dst_end = dst + sample_count;
while (dst != dst_end)
{
lock_guard<recursive_mutex> lock(_mutex);
float *const data = new float[end_sample - start_sample];
- memcpy(data, (float*)_data + start_sample, sizeof(float) *
+ memcpy(data, (float*)_data.data() + start_sample, sizeof(float) *
(end_sample - start_sample));
return data;
}
dest_ptr = e0.samples + prev_length;
// Iterate through the samples to populate the first level mipmap
- const float *const end_src_ptr = (float*)_data +
+ const float *const end_src_ptr = (float*)_data.data() +
e0.length * EnvelopeScaleFactor;
- for (const float *src_ptr = (float*)_data +
+ for (const float *src_ptr = (float*)_data.data() +
prev_length * EnvelopeScaleFactor;
src_ptr < end_src_ptr; src_ptr += EnvelopeScaleFactor)
{
lock_guard<recursive_mutex> lock(_mutex);
const size_t size = (end_sample - start_sample) * _unit_size;
- memcpy(data, (const uint8_t*)_data + start_sample * _unit_size, size);
+ memcpy(data, (const uint8_t*)_data.data() + start_sample * _unit_size, size);
}
void LogicSnapshot::reallocate_mipmap_level(MipMapLevel &m)
dest_ptr = (uint8_t*)m0.data + prev_length * _unit_size;
// Iterate through the samples to populate the first level mipmap
- const uint8_t *const end_src_ptr = (uint8_t*)_data +
+ const uint8_t *const end_src_ptr = (uint8_t*)_data.data() +
m0.length * _unit_size * MipMapScaleFactor;
- for (src_ptr = (uint8_t*)_data +
+ for (src_ptr = (uint8_t*)_data.data() +
prev_length * _unit_size * MipMapScaleFactor;
src_ptr < end_src_ptr;)
{
assert(_data);
assert(index < _sample_count);
- return unpack_sample((uint8_t*)_data + index * _unit_size);
+ return unpack_sample((uint8_t*)_data.data() + index * _unit_size);
}
void LogicSnapshot::get_subsampled_edges(
namespace data {
Snapshot::Snapshot(int unit_size) :
- _data(NULL),
_sample_count(0),
_capacity(0),
_unit_size(unit_size)
Snapshot::~Snapshot()
{
lock_guard<recursive_mutex> lock(_mutex);
- free(_data);
}
uint64_t Snapshot::get_sample_count() const
assert(_capacity >= _sample_count);
if (new_capacity > _capacity) {
_capacity = new_capacity;
- _data = realloc(_data, (new_capacity * _unit_size) + sizeof(uint64_t));
+ _data.resize((new_capacity * _unit_size) + sizeof(uint64_t));
}
}
uint64_t Snapshot::capacity() const
{
lock_guard<recursive_mutex> lock(_mutex);
- return _capacity;
+ return _data.size();
}
void Snapshot::append_data(void *data, uint64_t samples)
set_capacity(_sample_count + samples);
}
- memcpy((uint8_t*)_data + _sample_count * _unit_size,
+ memcpy((uint8_t*)_data.data() + _sample_count * _unit_size,
data, samples * _unit_size);
_sample_count += samples;
}
#include <thread>
#include <mutex>
+#include <vector>
namespace pv {
namespace data {
protected:
mutable std::recursive_mutex _mutex;
- void *_data;
+ std::vector<uint8_t> _data;
uint64_t _sample_count;
uint64_t _capacity;
int _unit_size;