Jump to content
  • Advertisement
Sign in to follow this  
Atash

Object array consistency

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

(C++) If I'm storing three floats in an object, and keep three of those objects in an array, will the array of those three objects be the exact equivalent of nine floats in a row? Basically, is there any extra luggage in an object besides the declared items? Thanks in advance

Share this post


Link to post
Share on other sites
Advertisement
The answer to that question is compiler/platform specific. Generally, however, if the class has no virtual methods, and the total size of its member variables are divisible by 32bits, then the answer is yes. If the class has virtual methods, then some extra space is allocated for the virtual function table. Its best if you do not rely on the object arranging its memory in any particular way, however, or any particular size, as its up to the compiler and you have to way to control it.

Share this post


Link to post
Share on other sites
Pretty much correct, but you CAN control it. In MSVC++, you do this with #pragma pack, which Google.

Share this post


Link to post
Share on other sites
Quote:
Original post by TheTroll
You can not guarentee then will be be next to each other in memory.

theTroll


This is a little ambiguous...

Arrays are garunteed to be sequential in memory, which is why you need to specify the size when you create one, unlike a linked list, or other node-based data structure.

However, depending on the compiler/platform/debug settings, there may be pad bytes in between objects. You may be technically correct (depending on different factors mentioned above), but conceptualy, arrays are sequential in memory.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!