c++ - Most efficient way of accessing coordinates -
given following definition
union { double coords[3]; struct { double x,y,z; }; } p;
it possible access coordinates of 3d point both index , name (both ways have advantages). equivalent? more precisely: following expressions
... p.coords[0] ... p.x ... ... p.coords[1] ... p.y ... ... p.coords[2] ... p.z ...
(pairwise, each line) generate same (assembly) code? there difference in efficiency between 2 ways of accessing coordinate?
p.x,...
might faster, there's not difference 1 notice. when use array, there time spent on multiplication size of each double in given index desired memory address; in other method (p.x,...
) compiler knows address accessing calculation not required. however, if compiler smart enough figure out constant numbers, there no difference.
Comments
Post a Comment