Sign in to follow this  
Fourty_Two

Passing CComPtr as parameter

Recommended Posts

Fourty_Two    145
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
Oluseyi    2103
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
Fourty_Two    145
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this