Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #80767

Re: "Nearly a quarter-century later, why is C++ still so popular?"

From Juha Nieminen <nospam@thanks.invalid>
Newsgroups comp.lang.c++
Subject Re: "Nearly a quarter-century later, why is C++ still so popular?"
Date 2021-08-02 10:23 +0000
Organization Aioe.org NNTP Server
Message-ID <se8h2t$699$1@gioia.aioe.org> (permalink)
References (4 earlier) <chine.bleu-DA14A8.07525728072021@reader.eternal-september.org> <sdtja3$17il$1@gioia.aioe.org> <0d40ea68-6b4f-4ac9-bdda-47f280aa3b84n@googlegroups.com> <se5lug$vfo$1@gioia.aioe.org> <c87155ac-7fc1-4607-af90-473af3082efan@googlegroups.com>

Show all headers | View raw


Öö Tiib <ootiib@hot.ee> wrote:
> Indeed but I lack imagination how even to use that traditional class
> design within some concrete number crunching example.

Suppose you are handling large triangle meshes where each vertex has quite
a lot of data. Rather obviously you have the vertex 3D position, but you
may also have texture UV coordinates for that vertex, a normal vector at
that vertex, its color, its brightness, and any other number of values that
may be needed for rendering the triangle mesh.

It would be a nice design to create a vertex class (or perhaps struct)
where every one of those types of data related to a verted has been
collected. So it could look something like:

class Vertex
{
    float position[3];
    float uv_coords[2];
    float environment_map_coords[2];
    float normal_vector[3];
    unsigned char color_rgba[4];

 public:
    // ...
};

That's really nice designwise. Not so nice in terms of performance.
Most often you want to do some operation to all vertices, and this
operation only cares about one or two of those member variables and
doesn't need the rest.

For example, suppose you want to transform the mesh in some manner,
by modifying its position values. Even if all the Vertex objects are
in an array, and even if you traverse the array linearly, you will
be jumping in large steps from one Vertex to the next, most probably
having a cache miss every time.

If, instead, you had an array that only contains the position coordinates
of all the vertices and nothing more, it will be much more compact, and
traversing it from beginning to end will cause significantly less
cache misses.

Or suppose you wanted to do some operations to the color of each vertex.
Again, you would be jumping in large steps from one Vertex object to
the next. If all the colors were exclusively in an array, then they
would be packed as compactly as possible, and a linear traversal would
thus be much more efficient.

(This is the idea with Data Oriented Design.)

Back to comp.lang.c++ | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

"Nearly a quarter-century later, why is C++ still so popular?" Lynn McGuire <lynnmcguire5@gmail.com> - 2021-07-27 14:59 -0500
  Re: "Nearly a quarter-century later, why is C++ still so popular?" Siri Cruise <chine.bleu@yahoo.com> - 2021-07-27 13:48 -0700
    Re: "Nearly a quarter-century later, why is C++ still so popular?" Vir Campestris <vir.campestris@invalid.invalid> - 2021-07-27 22:05 +0100
      Re: "Nearly a quarter-century later, why is C++ still so popular?" Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-07-27 14:23 -0700
        Re: "Nearly a quarter-century later, why is C++ still so popular?" legalize+jeeves@mail.xmission.com (Richard) - 2021-08-05 19:49 +0000
          Re: "Nearly a quarter-century later, why is C++ still so popular?" Jorgen Grahn <grahn+nntp@snipabacken.se> - 2021-08-19 20:08 +0000
            Re: "Nearly a quarter-century later, why is C++ still so popular?" Siri Cruise <chine.bleu@yahoo.com> - 2021-08-19 18:20 -0700
              Re: "Nearly a quarter-century later, why is C++ still so popular?" Juha Nieminen <nospam@thanks.invalid> - 2021-08-20 06:13 +0000
              Re: "Nearly a quarter-century later, why is C++ still so popular?" Jorgen Grahn <grahn+nntp@snipabacken.se> - 2021-08-20 06:17 +0000
                Re: "Nearly a quarter-century later, why is C++ still so popular?" Siri Cruise <chine.bleu@yahoo.com> - 2021-08-20 00:03 -0700
                Re: "Nearly a quarter-century later, why is C++ still so popular?" Juha Nieminen <nospam@thanks.invalid> - 2021-08-20 11:03 +0000
                Re: "Nearly a quarter-century later, why is C++ still so popular?" mickspud@downthefarm.com - 2021-08-20 15:19 +0000
              Re: "Nearly a quarter-century later, why is C++ still so popular?" "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2021-08-20 14:26 +0200
                Re: "Nearly a quarter-century later, why is C++ still so popular?" Öö Tiib <ootiib@hot.ee> - 2021-08-29 23:40 -0700
    Re: "Nearly a quarter-century later, why is C++ still so popular?" Cholo Lennon <chololennon@hotmail.com> - 2021-07-27 21:01 -0300
    Re: "Nearly a quarter-century later, why is C++ still so popular?" Juha Nieminen <nospam@thanks.invalid> - 2021-07-28 08:16 +0000
      Re: "Nearly a quarter-century later, why is C++ still so popular?" "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2021-07-28 16:22 +0200
        Re: "Nearly a quarter-century later, why is C++ still so popular?" Siri Cruise <chine.bleu@yahoo.com> - 2021-07-28 07:53 -0700
          Re: "Nearly a quarter-century later, why is C++ still so popular?" "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2021-07-28 21:23 +0200
            Re: "Nearly a quarter-century later, why is C++ still so popular?" Siri Cruise <chine.bleu@yahoo.com> - 2021-07-28 14:16 -0700
          Re: "Nearly a quarter-century later, why is C++ still so popular?" Juha Nieminen <nospam@thanks.invalid> - 2021-07-29 06:53 +0000
            Re: "Nearly a quarter-century later, why is C++ still so popular?" Öö Tiib <ootiib@hot.ee> - 2021-07-29 09:31 -0700
              Re: "Nearly a quarter-century later, why is C++ still so popular?" MrSpud_71i5@slwgrcbmd1l7yi1.org - 2021-07-30 11:21 +0000
              Re: "Nearly a quarter-century later, why is C++ still so popular?" Juha Nieminen <nospam@thanks.invalid> - 2021-08-01 08:28 +0000
                Re: "Nearly a quarter-century later, why is C++ still so popular?" Öö Tiib <ootiib@hot.ee> - 2021-08-01 05:49 -0700
                Re: "Nearly a quarter-century later, why is C++ still so popular?" Juha Nieminen <nospam@thanks.invalid> - 2021-08-02 10:23 +0000
                Re: "Nearly a quarter-century later, why is C++ still so popular?" MrSpud_rLY23@_h_.co.uk - 2021-08-02 15:05 +0000
                Re: "Nearly a quarter-century later, why is C++ still so popular?" Öö Tiib <ootiib@hot.ee> - 2021-08-03 04:57 -0700
                Re: "Nearly a quarter-century later, why is C++ still so popular?" Juha Nieminen <nospam@thanks.invalid> - 2021-08-03 12:16 +0000
                Re: "Nearly a quarter-century later, why is C++ still so popular?" Öö Tiib <ootiib@hot.ee> - 2021-08-03 06:01 -0700
                Re: "Nearly a quarter-century later, why is C++ still so popular?" Ian Collins <ian-news@hotmail.com> - 2021-08-08 13:03 +1200
                Re: "Nearly a quarter-century later, why is C++ still so popular?" "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-08-07 22:43 -0700
            Re: "Nearly a quarter-century later, why is C++ still so popular?" Vir Campestris <vir.campestris@invalid.invalid> - 2021-08-01 21:40 +0100
          Re: "Nearly a quarter-century later, why is C++ still so popular?" Chris Vine <chris@cvine--nospam--.freeserve.co.uk> - 2021-07-29 09:53 +0100
          Re: "Nearly a quarter-century later, why is C++ still so popular?" Manfred <noname@add.invalid> - 2021-07-30 13:51 +0200
      Re: "Nearly a quarter-century later, why is C++ still so popular?" Manfred <noname@add.invalid> - 2021-07-30 13:40 +0200
  Re: "Nearly a quarter-century later, why is C++ still so popular?" Bonita Montero <Bonita.Montero@gmail.com> - 2021-07-28 04:05 +0200
    Re: "Nearly a quarter-century later, why is C++ still so popular?" MrSpud_oyam9ltRb0@khlkg.info - 2021-07-28 09:30 +0000
  Re: "Nearly a quarter-century later, why is C++ still so popular?" Bo Persson <bo@bo-persson.se> - 2021-07-28 08:19 +0200
  Re: "Nearly a quarter-century later, why is C++ still so popular?" "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-08-03 13:10 -0700
    Re: "Nearly a quarter-century later, why is C++ still so popular?" Lynn McGuire <lynnmcguire5@gmail.com> - 2021-08-03 18:37 -0500
      Re: "Nearly a quarter-century later, why is C++ still so popular?" Cholo Lennon <chololennon@hotmail.com> - 2021-08-05 18:17 -0300
  Re:"Nearly a quarter-century later, why is C++ still so popular?" Blue Hat <blue_hat@hackershaven.com.jm> - 2021-08-08 13:33 -0500

csiph-web