I get a continuous stack overflow error when trying to test this little program to test the performance difference between Structure of Arrays vs Array of Structure. I'm clearly doing something wrong, but I have a really hard time figuring it out. Is anyone able to help?
#include "stdafx.h"
#include <vector>
#define NUM_ITEMS 10000000
struct Vector3 {
Vector3() : x(0.0f), y(0.0f), z(0.0f) {}
float x, y, z;
Vector3 operator+=(const Vector3& v) {
Vector3 v_new;
v_new.x = this->x + v.x;
v_new.y = this->y + v.y;
v_new.z = this->z + v.z;
return v_new;
}
};
struct SoA {
SoA() : pos(NUM_ITEMS), vel(NUM_ITEMS) {}
std::vector<Vector3> pos, vel;
};
struct AoS {
Vector3 pos, vel;
};
int main()
{
std::vector<AoS> entities[NUM_ITEMS];
for (int i = 0; i < entities->size(); i++) {
entities->at(i).pos += entities->at(i).vel;
}
SoA entityManager;
for (int i = 0; 1 < NUM_ITEMS; i++) {
entityManager.pos[i] += entityManager.vel[i];
}
return 0;
}
Aucun commentaire:
Enregistrer un commentaire