This topic is now archived and is closed to further replies.

Problem with Pointer Array...

This topic is 5617 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post

Link to post
Share on other sites
I guess you have some unnecessary stars in your code
Here''s what I would do;

CVertex *verts = new CVertex[numberOfVerts];

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

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

by the way is your variable myFile is of type FILE* or FILE? If it is a pointer(FILE*) drop & in front as well..

Share this post

Link to post
Share on other sites
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.


[edited by - Gammastrahler on July 26, 2002 11:15:00 AM]

Share this post

Link to post
Share on other sites
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..

Share this post

Link to post
Share on other sites