Problem with Pointer Array...

Started by
2 comments, last by Gammastrahler 21 years, 9 months ago
hi, i have an array of pointers CVertex **verts; this array is allocated as verts = new CVertex* [numberOfVerts]; the problem occurs when i want to write this array to a file: fwrite(*verts, sizeof(CVertex) * numberOfVerts, 1, &myFile); it just doesnt work! the data in the file is nothing than fubar! can someone help me? thanks Gammastrahler
Advertisement
I guess you have some unnecessary stars in your code
Here''s what I would do;

allocation;
CVertex *verts = new CVertex[numberOfVerts];

writing;
fwrite(verts, sizeof(CVertex) * numberOfVerts, 1, &myFile);

you don''t need a pointer to pointer (aka **)

Note;
by the way is your variable myFile is of type FILE* or FILE? If it is a pointer(FILE*) drop & in front as well..
-----------my quote is under construction
thanks mentat,

but i have used **verts instead of *verts because i want to have an array of pointers to the vertices. this has two reasons:

1.) each vertex structure has many bytes, maybe too much , so i think it would be more efficient.

2.) it is just comfortable if i pass pointers to functions
that change something in the vertex and i dont have to
reassign it to my array.

thanks
Gammastrahler

[edited by - Gammastrahler on July 26, 2002 11:15:00 AM]
for 1. no, it won''t be more efficient. in fact it will be far less efficient when you try sending that data to video driver. it is almost impossible to use a vertex array, because yours is vertex array of pointers.. and I can see a problem if your structure has many bytes. actually it should have.. normals, texture coordinates.. sth around 8 bytes at least, but usually more.. in short, you are on the wrong way..

for 2, you can also send your variables by reference. do you know what & does? anyway.. do not want to push you, but i think you should reconsider..

as for your ** implementation.. if you still want to use it, you have some bugs there in your fwrite call..


hope that helps..
-----------my quote is under construction

This topic is closed to new replies.

Advertisement