Jump to content
  • Advertisement
Sign in to follow this  
Fourty_Two

Passing CComPtr as parameter

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

Are there any rules to follow when passing CComPtr's as parameters? If you pass by value you get a copy that is released at the end of the function (more overhead), and if I pass by reference the debug reports unreleased memory from my IDirect3DDevice8 object (which gets passed around a lot for rendering and what not.) Should my internal classes (Sprites, textured quads) just maintain a normal pointer to the device? Thanks

Share this post


Link to post
Share on other sites
Advertisement
I think you're doing things backwards. You should structure things such that data gets passed to the device encapsulation for rendering rather than the other way around.

There's no inherent problem with passing CComPtrs. They allow you, as any good smart pointer does, to maintain normal pointer semantics. This means that deciding whether to pass by value or by reference is a question of whether the object is to be modified or not (if not, pass by value). If you're concerned about overhead but will not be modifying the pointer, pass by const reference.

Share this post


Link to post
Share on other sites
I understand what you're saying about passing to the device, but I haven't had much experience with large, multiclass projects. Are there any good references on how to manage and organize that method?

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!