[Libreoffice] Using STL for xml2cmp (2)

David Tardon dtardon at redhat.com
Thu Sep 30 00:05:03 PDT 2010

On Thu, Sep 30, 2010 at 02:19:03PM +0900, Seo Sanghyeon wrote:
> Attached patch removes DynamicList and migrate its users from
> DynamicList<T> to std::vector<T *>.
> <vector> header is included. "list.hxx" is not removed because it is
> still used for List class.


std::vector<T*> is not a correct replacement for DynamicList<T>, because
the latter manages the lifetime of its members, which std::vector does
not do, therefore every remove causes a memory leak. std::vector (or,
maybe, std::deque) is a suitable replacement for List. For DynamicList,
you have basically the following options:

1. track all removals from any DynamicList (including destructions)
   and add explicit delete of affected items
2. revamp DynamicList into a wrapper over std::vector (std::deque),
   that calls delete on the to-be-removed item(s) (so you'll end with
   the same class we have now, just with different implementation...)
3. use boost::ptr_vector (or boost::ptr_deque) (this is what I'd use,
   but others may be opposed to introducing a dependency on boost to
4. use std::vector<boost::shared_ptr<T> > (dep. on boost, again)


More information about the LibreOffice mailing list