On 05.12.2016 17:11 Mark Olesen wrote:
> It appears that providing a requested size will just allocate more
> memory than will be utilized. That is, the gap buffer will only use
> preferredGapSize bytes of memory. The rest will be wasted until
> reallocate_with_gap is called, which creates an entirely new buffer and
> deletes the old.
Okay, I see (checked). Thanks again for the report, I'll commit a fix in
FLTK 1.4 (branch-1.4).
> As a side note, Fl_Text_Display::buffer( Fl_Text_Buffer *buf ) does not
> appear to delete mBuffer if it is not null.
>
> if ( mBuffer != 0 ) {
> // we must provide a copy of the buffer that we are deleting!
> char *deletedText = mBuffer->text();
> buffer_modified_cb( 0, 0, mBuffer->length(), 0, deletedText, this );
> free(deletedText);
> mNBufferLines = 0;
> mBuffer->remove_modify_callback( buffer_modified_cb, this );
> mBuffer->remove_predelete_callback( buffer_predelete_cb, this );
> /* ---> here mBuffer should be deleted: delete mBuffer <---- */
> }
>
> /* Add the buffer to the display, and attach a callback to the buffer for
> receiving modification information when the buffer contents change */
> mBuffer = buf;
Well, it's hard to say if this is a bug or intentional. I believe it's
intentional though:
I checked the docs, and the behavior WRT the old (replaced) buffer is
not documented. However, the following *is* documented: "Multiple text
widgets can be associated with the same text buffer."
I take it that the Fl_Text_Display widget must not destroy the
associated Fl_Text_Buffer because the text buffer can still be
associated with another Fl_Text_Display or Fl_Text_Editor widget. Hence
it is the caller's responsibility to dispose of the text buffer once it
is no longer used [1]. I think this should be documented, but the code
is correct.
[1] It could also be used for something else, for instance to store (and
keep) the text in the buffer. That buffer could also be associated with
the same or another display or editor widget later.
Comments, anybody?
> anyway...
... thanks for the report.