Jump to content
  • Advertisement


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


Creating some arrays

This topic is 6376 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''m at the moment coding a routine, where i''m going trough a cycle of faces that are stored in an array. The purpose of that routine, is to check if a face is inside a cube. If it is, i increment a variable, otherwise not. So, in result i will get a number! Now, i want to create an array inside a structure, to hold that list of faces. I could do it with linked lists, but i wanna try with arrays, so, is this possible ? Structure: typedef struct portais { int num; Faces data; float planex[2]; float planey[2]; float planez[2]; struct portais *next; }*portals; portals init_portals; portals next_portals; the above is my data structure, so i wanna add an array to that structure at runtime. something like this: Faces *Temp = new Temp[number_of_faces]; next_portals->dados = Temp;

Share this post

Link to post
Share on other sites
well you cant create an array like normal if it isnt a constant size. for some reason, you just cant. even tho you should. but.. you can still do it.

the structure must be kept a constant size, so you need to use a pointer to the array instead of having the array inside the structure. to do this then the pointer points to the first item. when initializing the structure (use classes btw) just do something like:

Faces *Data = malloc( sizeof(Faces) * number_of_faces );

maybe what you suggested to yourself would work (with the ''new'' keyword) but i dont use ''new'' and ''delete'' cause i really just prefer malloc() and free().

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!