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

Started by
3 comments, last by johnnyBravo 19 years, 11 months ago
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
Advertisement
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
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]
I am always open to feedback, positive or negative...
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
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!   |                +------------+ 

This topic is closed to new replies.

Advertisement