Converting (casting?) a dynamic array to a fixed array?

Adam D. Ruppe via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun May 3 19:50:45 PDT 2015


On Monday, 4 May 2015 at 02:47:24 UTC, WhatMeWorry wrote:
>         glBufferData(GL_ARRAY_BUFFER, verts.sizeof, &verts, 
> GL_STATIC_DRAW);

Try

(GL_ARRAY_BUFFER, verts.length, verts.ptr, GL_STATIC_DRAW)

or maybe:

(GL_ARRAY_BUFFER, verts.length * verts[0].sizeof, verts.ptr, 
GL_STATIC_DRAW)

I'm not sure exactly what the function needs, but using the 
.length and .ptr properties on a dynamic array will probably work 
better than casting, and definitely work better than casting the 
address of it. (A dynamic array is actually a struct { size_t 
length; T* ptr; } object instead of raw memory like a static 
array, so taking the address of it actually gives the address of 
that length variable, not the data. the ptr attribute gets the 
pointer to the data. BTW static arrays also have .length and .ptr 
properties you can use the same way.)


More information about the Digitalmars-d-learn mailing list