Skip to main content
gamedev.net
🔒 Locked

Filling Array with different types

Started by dabx11 Jul 31, 2002 at 6:35 AM 3 replies 300+ views
Original Post
dabx11
dabx11
I''m trying to fill an array/memory with different types of data, kinda like this. example.... byte B[1024]; void* pB = B; *(float*)pB++ = (float)10; *(byte *)pB++ = (byte)5; *(int *)pB++ = (int)15; causes this error..doesn''t know how to increase the pointer error C2036: ''void *'' : unknown size but something like this works ok..but the pointer doesn''t change to the address after the float. *(float*)pB = (float)10; so how can I get pB to point after the float...or maybe i''m missing an easier way of doing this..
mentat
mentat
instead of using void*, use your byte array..


int ind = 0;
b[ind] = somebytedata;
ind += sizeof(byte);
*((float*)&b[ind]) = (float)somefloatdata;


however, even if it works, it is ugly.. why do you want to do this in the first place? Can't you use a struct or sth?

EDIT: he he, cannot post i as index (i in brackets means italics), changed to ind

[edited by - mentat on July 31, 2002 7:49:25 AM]
-----------my quote is under construction
LessBread
LessBread
quote:
Original post by dabx11
I'm trying to fill an array/memory with different types of data, kinda like this.

example....
byte B[1024];
void* pB = B;

*(float*)pB++ = (float)10;
*(byte *)pB++ = (byte)5;
*(int *)pB++ = (int)15;

causes this error..doesn't know how to increase the pointer
error C2036: 'void *' : unknown size

but something like this works ok..but the pointer doesn't change to the address after the float.
*(float*)pB = (float)10;

so how can I get pB to point after the float...or maybe i'm missing an easier way of doing this..


Um, yeah, a better way, but um, here's another hack

byte B[1024];
byte* pB = B;

*(pB += sizeof(float)) = (float)10.0;
*pB++ = (byte)5;
*(pB += sizeof(int)) = (int)15;

I haven't tested this. Those += aren't gonna cut it.
How do you propose retrieving the values?

int i = 0;
*( pB + i ) = (float)10.0; i += sizeof(float);
*( pB + i ) = (byte)5; i += sizeof(byte);
*( pB + i ) = (int)15; i += sizeof(int);




[edited by - lessbread on July 31, 2002 7:49:50 AM]
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
dabx11
dabx11
Thanks guys..i''ve got it working now...


what I was doing is storing information about a mesh, and I needed to convert it to a vertex buffer depending on the vertex format...so it''s kinda like a dynamic structure.


  

class CVertexBuffer {
public:
CVertexBuffer(){};

void RefreshVertexBuffer();

vector<D3DXVECTOR3> Position;
vector<D3DXVECTOR3> Normal;
vector<D3DXCOLOR> Diffuse;
vector<D3DXCOLOR> Specular;
vector<D3DXVECTOR2> Tex1;
vector<D3DXVECTOR2> Tex2;
vector<D3DXVECTOR2> Tex3;
vector<D3DXVECTOR2> Tex4;
vector<D3DXVECTOR2> Tex5;
vector<D3DXVECTOR2> Tex6;
vector<D3DXVECTOR2> Tex7;
vector<D3DXVECTOR2> Tex8;
DWORD VertexFormat;
};

[\source]

as you can see, the D3DVECTOR3 uses floats..and the D3DXCOLOR uses DWORD....
mentat
mentat
well, I don''t exactly get the meaning of your last post, but I can say that, using stl vector to store the vertices is a SUICIDE!!!
-----------my quote is under construction

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.