Help needed
Hi.
I have a class that handles the creation of surfaces and puts them in a linked list with a structure as below. I know I do not need the surface description in the struct but convince me why not.
struct SurfList
{
LPDIRECTDRAWSURFACE7 lpddSurface;
DDSURFACEDESC2 ddSurfDesc2;
SurfList *lpNext;
SurfList *lpPrev;
};
As for the question:
When the class(g_cSurface) creates a new surface it returns LPDIRECTDRAWSURFACE7. I want to destroy this surface.
Since the surface is declared first in the struct, does the address of the surface correspond to the start of the structure (dumb question), I mean if I declare a new pointer of type SurfList in the delete function: could I use the same address as what the surface has? ie SurfList *lpCurrent=lpddSurfaceToDelete;
What should I do, please?
Edited by - clabinsky on December 18, 2001 10:13:11 PM
Edited by - clabinsky on December 18, 2001 10:14:09 PM
Edited by - clabinsky on December 18, 2001 10:39:51 PM
Or do I have to do something like this:
<br>
<b>
bool CSurface::DeleteSurface(LPDIRECTDRAWSURFACE7 lpddSurf)
{
SurfList *lpCurrent; //Temporary struct pointer
lpCurrent=m_lpFirstOffScreen; //Assign to first surface in list
while(lpCurrent)
{
if(lpCurrent->lpddSurface==lpddSurf)
{//Surface Found
lpCurrent->lpNext->lpPrev=lpCurrent->lpPrev;
lpCurrent->lpPrev->lpNext=lpCurrent->lpNext;
lpCurrent->lpddSurface->Release();
lpCurrent->lpddSurface=NULL;
lpCurrent->lpNext=lpCurrent->lpPrev=0;
delete lpCurrent;
lpCurrent=0;
return true; //Surface deleted
} //end if
lpCurrent=lpCurrent->lpNext;
} //end while
return false; //Surface not found
}
</b><br>
Please?
<br>
<b>
bool CSurface::DeleteSurface(LPDIRECTDRAWSURFACE7 lpddSurf)
{
SurfList *lpCurrent; //Temporary struct pointer
lpCurrent=m_lpFirstOffScreen; //Assign to first surface in list
while(lpCurrent)
{
if(lpCurrent->lpddSurface==lpddSurf)
{//Surface Found
lpCurrent->lpNext->lpPrev=lpCurrent->lpPrev;
lpCurrent->lpPrev->lpNext=lpCurrent->lpNext;
lpCurrent->lpddSurface->Release();
lpCurrent->lpddSurface=NULL;
lpCurrent->lpNext=lpCurrent->lpPrev=0;
delete lpCurrent;
lpCurrent=0;
return true; //Surface deleted
} //end if
lpCurrent=lpCurrent->lpNext;
} //end while
return false; //Surface not found
}
</b><br>
Please?
In short the answer would be yes but you would still need to de-reference. I am not entirely sure of your motives here but I am assuming that you are trying to avoid de-referencing for some reason. I suppose you could de-ref the original pointer, cast it, and release it but the notation would be ugly as hell and buy you almost nothing once it is compiled.
Also - While I have hated them greatly off and on I would HIGHLY recommend looking into STL rather than writing your own linked-list stuff. They are fast, they work, and are butt-simple to use. Here is a decent link to a site:
http://www.sgi.com/tech/stl/
Game Programming Gems I has some good information as well.
Also - While I have hated them greatly off and on I would HIGHLY recommend looking into STL rather than writing your own linked-list stuff. They are fast, they work, and are butt-simple to use. Here is a decent link to a site:
http://www.sgi.com/tech/stl/
Game Programming Gems I has some good information as well.
Thanks for the reply.
I guess I could do something like
...
bool CSurface::DeleteSurface(LPDIRECTDRAWSURFACE7 lpddSurf)
{
SurfList *lpCurrent; //Temporary struct pointer
lpCurrent=(SurfList *)lpddSurf;
...
if so, this saves a lot of time since I do not need to traverse the list at all. I know which structure by knowing the surface and thus can de reference straight away, first making sure if it is the first or last, and only one or middle of the list struct huh!
I´ll look into the STL but I figure knowing how to make it myself will give me an advatage using someone else´s
I guess I could do something like
...
bool CSurface::DeleteSurface(LPDIRECTDRAWSURFACE7 lpddSurf)
{
SurfList *lpCurrent; //Temporary struct pointer
lpCurrent=(SurfList *)lpddSurf;
...
if so, this saves a lot of time since I do not need to traverse the list at all. I know which structure by knowing the surface and thus can de reference straight away, first making sure if it is the first or last, and only one or middle of the list struct huh!
I´ll look into the STL but I figure knowing how to make it myself will give me an advatage using someone else´s
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement