data-oriented-design

Data-oriented design in practice?

橙三吉。 提交于 2020-11-30 03:59:13
问题 There has been one more question on what data-oriented design is, and there's one article which is often referred to (and I've read it like 5 or 6 times already). I understand the general concept of this, especially when dealing with, for example, 3d models, where you'd like to keep all vertexes together, and not pollute your faces with normals, etc. However, I do have a hard time visualizing how data-oriented design might work for anything but the most trivial cases (3d models, particles,

Data-oriented design in practice?

对着背影说爱祢 提交于 2020-11-30 03:58:58
问题 There has been one more question on what data-oriented design is, and there's one article which is often referred to (and I've read it like 5 or 6 times already). I understand the general concept of this, especially when dealing with, for example, 3d models, where you'd like to keep all vertexes together, and not pollute your faces with normals, etc. However, I do have a hard time visualizing how data-oriented design might work for anything but the most trivial cases (3d models, particles,

How do I create a Multi-Layer Perceptron following DOD? Or how are dynamically allocated arrays stored?

不想你离开。 提交于 2019-12-25 02:55:17
问题 First of all, I'm new to this concept of DOD, and while new to it, I find it really exciting from a programmer perspective. I made a Multi-Layer Perceptron a while ago as an OO project for myself, and since I'm learning DOD now, I thought it would be nice to make it with this paradigm. struct Neuron { double bias; double error; }; struct Layer { Neuron* neurons; double* output; double** connections; unsigned numberNeurons; }; struct Network { unsigned numberInput; double* input; std::vector

Is cutting if statements by using function pointers going to be more efficient?

时间秒杀一切 提交于 2019-12-23 09:13:01
问题 So, there's this rule to try to pull if statements out of high repetition loops: for( int i = 0 ; i < 10000 ; i++ ) { if( someModeSettingOn ) doThis( data[i] ) ; else doThat( data[i] ) ; } They say, it's better to break it up, to put the if statement outside: if( someModeSettingOn ) for( int i = 0 ; i < 10000 ; i++ ) doThis( data[i] ) ; else for( int i = 0 ; i < 10000 ; i++ ) doThat( data[i] ) ; (In case you're saying "Ho! Don't optimize that yourself! The compiler will do it!") Sure the

Which one is faster ? Function call or Conditional if Statement?

青春壹個敷衍的年華 提交于 2019-12-21 04:40:59
问题 Please consider the branch prediction too before answering this question. I have some scenarios where i can replace a conditional statement with a call to a function with the help of function pointer.Some thing like this. (you can think of component based programming over inheritance for a similar type of senario) class Shape { float Area() { if(type == SQUARE) { return length*length; } else if(type == RECTANGLE) { return length*breadth; } } } The same class can be written like this. class

Is there a contiguously stored hash map data structure?

…衆ロ難τιáo~ 提交于 2019-12-08 02:54:18
问题 Think of collections of different types like Position , Color , Name . Instances of those can be connected by using the same key in the collection. Keys are global unique identifiers of 64 bit length. Currently, I use a hash map but this is not ideal. // custom types struct Position { float x, y, z; bool static; }; enum Color { RED, BLUE, GREEN }; // collections std::unordered_map<uint64_t, Position> positions; std::unordered_map<uint64_t, Color> colors; std::unordered_map<uint64_t, std:

C++ zero-cost abstraction for SoA/AoS memory layouts

徘徊边缘 提交于 2019-12-07 06:30:36
问题 Say I have a large code using Array of Structures (AoS) memory layout. I would like to build a zero-cost abstraction in C++ which allows me to switch between AoS and SoA with as little refactoring effort as possible. For instance take a class with access member functions struct Item{ auto& myDouble(){ return mDouble; } auto& myChar(){ return mChar; } auto& myString(){ return mString; } private: double mDouble; char mChar; std::string mString; }; which is used inside a container in a loop std:

Switching back and forth between Array of Structures (AoS) and Structure of Arrays (SoA)

我只是一个虾纸丫 提交于 2019-12-05 21:43:28
问题 One feature that plays a prominent role in many of the writings on data oriented design is that there are many cases where rather than AoS (array of structs): struct C_AoS { int foo; double bar; }; std::vector<C_AoS> cs; ... std::cout << cs[42].foo << std::endl; it is more efficient to arrange one's data in SoA (struct of arrays): struct C_SoA { std::vector<int> foo; std::vector<double> bar; }; C_SoA cs; ... std::cout << cs.foo[42] << std::endl; Now what I am looking for is a solution which

Which is most cache friendly?

蓝咒 提交于 2019-12-05 17:45:27
问题 I am trying to get a good grip on data oriented design and how to program best with the cache in mind. There's basically two scenarios that I cannot quite decide which is better and why - is it better to have a vector of objects, or several vectors with the objects atomic data? A) Vector of objects example struct A { GLsizei mIndices; GLuint mVBO; GLuint mIndexBuffer; GLuint mVAO; size_t vertexDataSize; size_t normalDataSize; }; std::vector<A> gMeshes; for_each(gMeshes as mesh) {

C++ zero-cost abstraction for SoA/AoS memory layouts

人走茶凉 提交于 2019-12-05 09:13:05
Say I have a large code using Array of Structures (AoS) memory layout. I would like to build a zero-cost abstraction in C++ which allows me to switch between AoS and SoA with as little refactoring effort as possible. For instance take a class with access member functions struct Item{ auto& myDouble(){ return mDouble; } auto& myChar(){ return mChar; } auto& myString(){ return mString; } private: double mDouble; char mChar; std::string mString; }; which is used inside a container in a loop std::vector<Item> vec_(1000); for (auto& i : vec_) i.myDouble()=5.; I would like to change the first