X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=pv%2Fsession.cpp;h=df09ff3b2ebc0b924a9158158de9a2362ab385db;hb=0a4162a4bd844574319f8b26b05f4fcdf837bb70;hp=fcd0e135b5a190972613e85ac79ada3f067b7023;hpb=5ccfc97e20bbea19b9bc37905dd4cf63ee1f6303;p=pulseview.git diff --git a/pv/session.cpp b/pv/session.cpp index fcd0e13..df09ff3 100644 --- a/pv/session.cpp +++ b/pv/session.cpp @@ -857,6 +857,9 @@ void Session::sample_thread_proc(function error_handler) assert(0); } + // Optimize memory usage + free_unused_memory(); + // We now have unsaved data unless we just "captured" from a file shared_ptr file_device = dynamic_pointer_cast(device_); @@ -868,6 +871,17 @@ void Session::sample_thread_proc(function error_handler) error_handler(tr("Out of memory, acquisition stopped.")); } +void Session::free_unused_memory() +{ + for (shared_ptr data : all_signal_data_) { + const vector< shared_ptr > segments = data->segments(); + + for (shared_ptr segment : segments) { + segment->free_unused_memory(); + } + } +} + void Session::feed_in_header() { cur_samplerate_ = device_->read_config(ConfigKey::SAMPLERATE); @@ -927,8 +941,6 @@ void Session::feed_in_logic(shared_ptr logic) { lock_guard lock(data_mutex_); - const size_t sample_count = logic->data_length() / logic->unit_size(); - if (!logic_data_) { // The only reason logic_data_ would not have been created is // if it was not possible to determine the signals when the @@ -942,8 +954,7 @@ void Session::feed_in_logic(shared_ptr logic) // Create a new data segment cur_logic_segment_ = shared_ptr( - new data::LogicSegment( - logic, cur_samplerate_, sample_count)); + new data::LogicSegment(logic, cur_samplerate_)); logic_data_->push_segment(cur_logic_segment_); // @todo Putting this here means that only listeners querying @@ -988,8 +999,7 @@ void Session::feed_in_analog(shared_ptr analog) // Create a segment, keep it in the maps of channels segment = shared_ptr( - new data::AnalogSegment( - cur_samplerate_, sample_count)); + new data::AnalogSegment(cur_samplerate_)); cur_analog_segments_[channel] = segment; // Find the analog data associated with the channel @@ -1021,6 +1031,8 @@ void Session::feed_in_analog(shared_ptr analog) void Session::data_feed_in(shared_ptr device, shared_ptr packet) { + static bool frame_began=false; + (void)device; assert(device); @@ -1042,6 +1054,7 @@ void Session::data_feed_in(shared_ptr device, case SR_DF_FRAME_BEGIN: feed_in_frame_begin(); + frame_began = true; break; case SR_DF_LOGIC: @@ -1062,6 +1075,7 @@ void Session::data_feed_in(shared_ptr device, } break; + case SR_DF_FRAME_END: case SR_DF_END: { { @@ -1069,7 +1083,10 @@ void Session::data_feed_in(shared_ptr device, cur_logic_segment_.reset(); cur_analog_segments_.clear(); } - frame_ended(); + if (frame_began) { + frame_began = false; + frame_ended(); + } break; } default: