Archived

This topic is now archived and is closed to further replies.

Using GetDevice(LPDIRECT3DDEVICE9 *....) is it slow, do i have to release?

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

Hi im designing my wrapper for dx and ive been using the GetDevice(LPDIRECT3DDEVICE9... to get the d3d device once the object has been initialised eg Vertex buffer, so i dont have to store the LPDIRECT3DDEVICE9 in my vertex buffer class. But im wondering if using get is bad and slow? and in the help file for the getDevice it says something about the d3d interface incrementing a count so after you use it you have to release it, do i have to release it? i thought that would release the whole thing. this is how im using it after the class that im using is already been initialised
void draw()
{
LPDIRECT3DDEVICE9 dd;
vertexBuffer->GetDevice(&dd);
dd->draw....
//should i put a dd->release() here?

}

thanks

Share this post


Link to post
Share on other sites
Whether or not it is slow is for you to benchmark to find out, but as for needing a Release() call, yes, you do, the SDK documentation mentions that GetDevice() increases the reference count on the object so failing to call Release() will result in a memory leak.

-Mezz

Share this post


Link to post
Share on other sites
Yes, you do need to release() the device, but not until the end of your program. There is no need to release the device every time you call a draw() function. I would put the device->release() function in your final function call (such as GameShutDown()).

Now for the GetDevice call. It may slow you down to grab a pointer to the device every time you call the draw() function. In my DirectX programs, I call GetDevice() once then store that pointer in a global variable. That way, when I call a render() function, I can just pass in that variable. Moreover, if I have a class object that has its own render function, I pass in the device pointer when I call that render function.

[edited by - Teric on May 19, 2004 10:18:19 AM]

Share this post


Link to post
Share on other sites
No, he needs to Release() it for every time the reference count is incremented, which IDirect3DVertexBuffer9::GetDevice() does, so, he needs to either Release() it for each draw call, or stick a big loop in his shut down routine that will Release() it the correct number of times, or he will get memory leaks. It''s easier in this case, and I think less error prone, to Release() it each draw call.

-Mezz

Share this post


Link to post
Share on other sites
As a general rule, whenever a D3D/D3DX function takes a pointer to an interface pointer (e.g. IDirect3DDevice9 **ppDevice or LPDIRECT3DDEVICE9 *ppDevice) you have to release the interface after you''re done with it.

                +------------+
Muhammad Haggag | Forum FAQ |
Optimize | Read it! |
+------------+

Share this post


Link to post
Share on other sites