Difference between revisions of "Talk:C++"
From GnuCash
(std::vector is better than std::list for most use-cases in Gnucash) |
|||
Line 3: | Line 3: | ||
JRalls: That's true, but most of the time we use GList to get a run-time extensible collection that can be iterated. Std::vector meets both of those requirements with vastly better performance and code size compared to std::list. Lists are better only in the case where one needs to frequently insert items into the middle or to reorder the items, both rather expensive operations for std::vector. I haven't found many places in Gnucash where the former is required, and only the Transaction splits list fits the latter. Note as well that GLib lacks a vector-like class, so the only extensible-and-iterable container is GList. | JRalls: That's true, but most of the time we use GList to get a run-time extensible collection that can be iterated. Std::vector meets both of those requirements with vastly better performance and code size compared to std::list. Lists are better only in the case where one needs to frequently insert items into the middle or to reorder the items, both rather expensive operations for std::vector. I haven't found many places in Gnucash where the former is required, and only the Transaction splits list fits the latter. Note as well that GLib lacks a vector-like class, so the only extensible-and-iterable container is GList. | ||
+ | |||
+ | :cstim: Absolutely. When explained this way, I totally agree: Most of our use case of a extensible collection should better use a std::vector. Only very few use cases better map on a std::list. But glib does not have an analogy of std::vector, only GList as an analogy to std::list, so that's why gnucash currently uses only that one. --[[User:Cstim|Cstim]] 03:09, 4 December 2013 (EST) |
Latest revision as of 08:09, 4 December 2013
std::vector vs. std::list
Christian Stimming commented in-line that "std::vector isn't the correct analogy to GList, std::list is".
JRalls: That's true, but most of the time we use GList to get a run-time extensible collection that can be iterated. Std::vector meets both of those requirements with vastly better performance and code size compared to std::list. Lists are better only in the case where one needs to frequently insert items into the middle or to reorder the items, both rather expensive operations for std::vector. I haven't found many places in Gnucash where the former is required, and only the Transaction splits list fits the latter. Note as well that GLib lacks a vector-like class, so the only extensible-and-iterable container is GList.
- cstim: Absolutely. When explained this way, I totally agree: Most of our use case of a extensible collection should better use a std::vector. Only very few use cases better map on a std::list. But glib does not have an analogy of std::vector, only GList as an analogy to std::list, so that's why gnucash currently uses only that one. --Cstim 03:09, 4 December 2013 (EST)