Jump to content
  • Advertisement
Sign in to follow this  
3DModelerMan

Memory alignment question

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

If I write a Vector3 class and declare the x,y,z members as _declspec(allign_16) (I might have got the syntax wrong there). Do member functions count towards data size? I want to have a dot product, and a cross product, and some other utility functions. Would I have to make sure the functions were aligned as well? And also, how do you make vectors take advantage of SIMD?

Share this post


Link to post
Share on other sites
Advertisement

If I write a Vector3 class and declare the x,y,z members as _declspec(allign_16) (I might have got the syntax wrong there). Do member functions count towards data size? I want to have a dot product, and a cross product, and some other utility functions. Would I have to make sure the functions were aligned as well? And also, how do you make vectors take advantage of SIMD?


A way to find out for yourself :)


In your code:
1. Create 2 Vector3's on the stack as an array (Vector3 v[2])
2. Set the Vector3 x, y, zs to unique values (e.g. v1 = {1, 2, 3} v2 = {4, 5, 6})
3. (optional but might be less confusing) Get the address of the 1st element of the Vector3 (&(v[0])) array and set it to some variable

Debugging:
4. Set a breakpoint right after the above code.
5. Debug your application

Viewing memory:
6. When the breakpoint hits, open Memory View. (Debug -> Windows -> Memory)
7. Drag the address of the 1st element in the Vector3 array into the Memory View's address textbox.
8. Right click in the middle of the Memory View (the area with a whole bunch of numbers) and select your data format (typically 32 bit, signed for a Vector3)
9. Look at how 1, 2, 3, 4, 5, 6 are laid out. Padding / alignment are clearly shown.

Share this post


Link to post
Share on other sites
This might be a good time to research how member functions work. Essentially, non-virtual member functions are almost exactly the same as a stand-alone or "free" function. You can think of a member function as a free function with an implicit "this" pointer parameter to the type. The "this" pointer would be const if the member function is const. The main difference is that member functions can access the private and protected members of the type.

If you're interested in how virtual member functions work, pretty much all compilers implement them with virtual member function lookup tables, or "vtable". Googling that term will be illuminating.

Share this post


Link to post
Share on other sites

This might be a good time to research how member functions work. Essentially, non-virtual member functions are almost exactly the same as a stand-alone or "free" function. You can think of a member function as a free function with an implicit "this" pointer parameter to the type. The "this" pointer would be const if the member function is const. The main difference is that member functions can access the private and protected members of the type.

If you're interested in how virtual member functions work, pretty much all compilers implement them with virtual member function lookup tables, or "vtable". Googling that term will be illuminating.


Ah. I see now. How can I make my vector class take advantage of SIMD instruction sets?

Share this post


Link to post
Share on other sites

[quote name='rip-off' timestamp='1319015802' post='4874214']
This might be a good time to research how member functions work. Essentially, non-virtual member functions are almost exactly the same as a stand-alone or "free" function. You can think of a member function as a free function with an implicit "this" pointer parameter to the type. The "this" pointer would be const if the member function is const. The main difference is that member functions can access the private and protected members of the type.

If you're interested in how virtual member functions work, pretty much all compilers implement them with virtual member function lookup tables, or "vtable". Googling that term will be illuminating.


Ah. I see now. How can I make my vector class take advantage of SIMD instruction sets?
[/quote]

Let the compiler do it's job.

Share this post


Link to post
Share on other sites


Let the compiler do it's job.


Which will make it shrug and move on.


SSE design. Follow the links from there on previous articles and stuff on gamasutra and original site.

Then just use the library from github, it's a solved problem.

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.

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!