# HG changeset patch # User John W. Eaton # Date 1317654220 14400 # Node ID c053740eb2aa3bcd350f0a416f0a21bd7d0194a9 # Parent 89789bc755a180990b71770d19fda74829991c7e improve memory use for the pager and diary streams (bug #34431) * pager.h, pager.cc (octave_pager_stream::reset, octave_pager_stream::do_reset): New functions. (octave_diary_stream::reset, octave_diary_stream::do_reset): New functions. * input.cc (octave_gets, get_user_input): Call octave_pager_stream::reset and octave_diary_stream::reset prior to printing prompt and getting input. diff --git a/src/input.cc b/src/input.cc --- a/src/input.cc +++ b/src/input.cc @@ -275,6 +275,9 @@ flush_octave_stdout (); + octave_pager_stream::reset (); + octave_diary_stream::reset (); + octave_diary << prompt; retval = interactive_input (prompt); @@ -794,6 +797,9 @@ flush_octave_stdout (); + octave_pager_stream::reset (); + octave_diary_stream::reset (); + octave_diary << prompt; std::string input_buf = interactive_input (prompt.c_str (), true); diff --git a/src/pager.cc b/src/pager.cc --- a/src/pager.cc +++ b/src/pager.cc @@ -334,6 +334,29 @@ pb->set_diary_skip (); } +// Reinitialize the pager buffer to avoid hanging on to large internal +// buffers when they might not be needed. This function should only be +// called when the pager is not in use. For example, just before +// getting command-line input. + +void +octave_pager_stream::reset (void) +{ + if (! instance) + instance = new octave_pager_stream (); + + instance->do_reset (); +} + +void +octave_pager_stream::do_reset (void) +{ + delete pb; + pb = new octave_pager_buf (); + rdbuf (pb); + setf (unitbuf); +} + octave_diary_stream *octave_diary_stream::instance = 0; octave_diary_stream::octave_diary_stream (void) : std::ostream (0), db (0) @@ -358,6 +381,29 @@ return *instance; } +// Reinitialize the diary buffer to avoid hanging on to large internal +// buffers when they might not be needed. This function should only be +// called when the pager is not in use. For example, just before +// getting command-line input. + +void +octave_diary_stream::reset (void) +{ + if (! instance) + instance = new octave_diary_stream (); + + instance->do_reset (); +} + +void +octave_diary_stream::do_reset (void) +{ + delete db; + db = new octave_diary_buf (); + rdbuf (db); + setf (unitbuf); +} + void flush_octave_stdout (void) { diff --git a/src/pager.h b/src/pager.h --- a/src/pager.h +++ b/src/pager.h @@ -68,8 +68,12 @@ static octave_pager_stream& stream (void); + static void reset (void); + private: + void do_reset (void); + static octave_pager_stream *instance; octave_pager_buf *pb; @@ -108,8 +112,12 @@ static octave_diary_stream& stream (void); + static void reset (void); + private: + void do_reset (void); + static octave_diary_stream *instance; octave_diary_buf *db;