internal representation of struct

so so at so.so
Fri Mar 18 13:12:40 PDT 2011


On Fri, 18 Mar 2011 18:34:19 +0200, lenochware <lenochware at gmail.com>  
wrote:

> Hello, I have array of type vertex_t vertices[] where vertex_t is:
>
> struct vertex_t {
>   float[3] xyz;
>   ubyte[4] color;
>   ...
> }
>
> Now, I would like use instead of array "float[3] xyz" "vec3f xyz", where  
> vec3f is:
>
> struct vec3f {
>   float x, y, z;
>
> ...some functions...
> }
>
> where I have defined some operators for adding and multipliing vectors  
> etc.
>
> Is it possible? "xyz" must be exactly 3 floats in memory because I am  
> sending
> vertices array pointer into OpenGL rendering pipeline.
> Will be struct vec3f represented just like 3 floats - aren't here some
> additional metadata - because structure contains also some functions?
>
> My additional question: What about effectivity? I would like keep struct
> vertex_t as simple as possible, because I need do calculations fast.  
> Will have
> replacing float array to structure some impact on speed?
>
> Thank you.

D struct is POD.
If you replace it with a struct, the speed is up to you since an array  
implementation might use cpu specific extensions.


More information about the Digitalmars-d mailing list