On Fri, Nov 25, 2005 at 03:51:28PM +0100, Jean-Marc Lasgouttes wrote:
> 
> I think the change of container from list to vector for ParagraphList
> is putting us in a bad situation. Remember the weird bug I had to
> solve with DEPM a few weeks ago: everytime you insert a paragraph in a
> document, all subsequent paragraphs are cloned and deleted because
> they have to move.
> 
> But the situation seems to be worse. Launch LyX and load
> Help>Introduction. See how the first paragraph has id 262. This
> probably means that the whole document has been
> allocated/deallocated/reallocated just be loading it. Strange.

std::vector<>::push_back copies its items when resizing is necessary.

We could faily simple work around coping actual paragraph contents by 
either using some std::vector<some_ref_counted_ptr<Paragraph> > 
instead of std::vector<Paragraph>, or by implementing some container
on top of std::vector<Paragraph> that forwards most functions but
uses a custom push_back that uses 'swap' on the contents instead of
copying it when resizing.

> Now, in Document>Settings, change the textclass to article. This gives
> 3 errors, since the chapter headings have been changed to Standard.
> But the error list does not work: it searches for id 994 (which was
> 266 before switching class: document allocated three more time), but
> 994 does not exist anymore, it is 1258 already :)

I think paragraph ids are an anachrnism. We have stable(!) doc iterators
nowadays, so positions could be indicated by those.

> My problem is that I do not know where and why this happens... But
> this cannot be good for performance or memory fragmentation anyway.
> 
> So, would it still be time to go back to std::list or something else?

This woul require reworking the doc iterator stuff as this relies
on fast access using integer offsets.

> Can we have a vector of share_ptr<Paragraph> or some other wicked
> construct?

This would be the first option mention above. I'd personally prefer
the second.

Andre'

Reply via email to