P
Peter Steiner
hi there!
my problem: i need arrays of float-triples (math vector). i need these
available in a flat float* array for batch processing (opengl). is an
array of POD structs with three float members each equivalent to a flat
array of floats in terms of memory layout?
ie. is the following code legal?
struct Vector {
float v[3];
};
Vector vectors[3];
float flatVectors[3][3];
memcpy((const void*)flatVectors, (void*)vectors, sizeof(float)*9);
// vectors now contains the same values in Vector::v as flatVectors
i suspect that struct member alignment, as applied by compilers,
forbids that kind of usage. is that true, and if so, is there a way to
circumvent that problem in a portable fashion?
i am interested in such a solution because i would like to implement a
convenient math vector class in a platform-independend, purely object
oriented program.
-- peter
my problem: i need arrays of float-triples (math vector). i need these
available in a flat float* array for batch processing (opengl). is an
array of POD structs with three float members each equivalent to a flat
array of floats in terms of memory layout?
ie. is the following code legal?
struct Vector {
float v[3];
};
Vector vectors[3];
float flatVectors[3][3];
memcpy((const void*)flatVectors, (void*)vectors, sizeof(float)*9);
// vectors now contains the same values in Vector::v as flatVectors
i suspect that struct member alignment, as applied by compilers,
forbids that kind of usage. is that true, and if so, is there a way to
circumvent that problem in a portable fashion?
i am interested in such a solution because i would like to implement a
convenient math vector class in a platform-independend, purely object
oriented program.
-- peter