Jump to content
  • Advertisement

Archived

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

Mezz

Types or Arrays?

This topic is 6912 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

This subject might have been debated before, but I''m not sure, and I''m trying to get a conclusive view on it. The question: Should coordinate/vertex data be held in arrays or structures? My own ideas: Arrays can be favoured over structures for a couple of reasons - in OpenGL; they are simple to pass efficiently (by glwhateverfv(); calls) and the elements can be accessed via index (i.e. useful in loops) I am not certain whether structures require more storage space, or have more overhead, so please clear that up for me if you can. I''m open to all views on this; so let us know. -Mezz

Share this post


Link to post
Share on other sites
Advertisement
Some structures might be padded up to machine word alignment; however, when working with floats on x86 machines, the structures will automatically be in multiples of DWORD, so there should be no "hidden" costs to the structures. Otherwise the only other possible overhead I can think of is if you gave your structures virtual methods in C++, or are using RTTI. Provided that the structure has no other data members, a simple cast of your structure will let OpenGL access the data easily. If the structure is actually a union between an array of floats and a named floats, you can access the contents with either indices or names(x, y, z, etc.) interchangeably.

This all depends, of course, on having a semi-reasonable compiler and a good understanding on how the structure looks in memory at runtime.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!