Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Vector of Objects vs Vector of Pointers And Memory Access Patterns

31 views
Skip to first unread message

Real Troll

unread,
Mar 23, 2020, 7:56:48 PM3/23/20
to
Memory access patterns are one of the key factors for writing efficient
code that runs over large data sets. In this blog post, you’ll see why
there might be a difference of almost 2.5x (in both directions!) when
working with a vector of pointers versus a vector of value types.

<https://www.bfilipek.com/2014/05/vector-of-objects-vs-vector-of-pointers.html>

Good luck.


Melzzzzz

unread,
Mar 24, 2020, 3:03:00 AM3/24/20
to
Hm, I find that vector of values is more efficient. Especially sorting
linked list by value exchange is more efficient then swapping pointers.
eg after sort just traversing list is much more efficent.

>
>


--
press any key to continue or any other to quit...
U ničemu ja ne uživam kao u svom statusu INVALIDA -- Zli Zec
Svi smo svedoci - oko 3 godine intenzivne propagande je dovoljno da jedan narod poludi -- Zli Zec
Na divljem zapadu i nije bilo tako puno nasilja, upravo zato jer su svi
bili naoruzani. -- Mladen Gogala

Öö Tiib

unread,
Mar 24, 2020, 3:10:17 AM3/24/20
to
Why projects use pointers to objects of their most massive data type,
and what alternatives to suggest?

If it is dynamic polymorphism then there is boost::base_collection
to consider.
If it is need for more control over life-time of single objects
then there are std::optional and std::variant to consider.
If it is need for sorting then there is boost::intrusive::set
to consider.
If it is because that way was easier to mock for unit testing,
then .. huh, consider trying more.
If it is because of desire to have our most massively used type
opaque then ... huh, consider dropping that stupid idea.
0 new messages