Types or Arrays?

Started by
0 comments, last by Mezz 23 years, 11 months ago
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
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.

This topic is closed to new replies.

Advertisement