IDirectDraw2::GetAvailableVidMem
HRESULT GetAvailableVidMem(LPDDSCAPS lpDDSCaps,
LPDWORD lpdwTotal, LPDWORD lpdwFree);
Gets the total amount of display memory available and the amount of display memory currently free. If NULL is passed to either lpdwTotal or lpdwFree, the value for that parameter is not returned.
·Returns DD_OK if successful, or one of the following error values otherwise:
DDERR_INVALIDOBJECT DDERR_NODIRECTDRAWHW
DDERR_INVALIDPARAMS DDERR_INVALIDCAPS
lpDDSCaps
Address of a DDSCAPS structure that contains the hardware capabilities of the surface.
lpdwTotal
Address of a doubleword to be filled in with the total amount of display memory available.
lpdwFree
Address of a doubleword to be filled in with the amount of display memory currently free.
The following C++ example demonstrates using IDirectDraw2::GetAvailableVidMem to determine both the total and free display memory available for texture map surfaces:
LPDIRECTDRAW2 lpDD2;
DDSCAPS ddsCaps;
DWORD dwTotal;
DWORD dwFree;
ddres = lpDD->QueryInterface(IID_IDirectDraw2,
&lpDD2); if (FAILED(ddres))
...
ddsCaps.dwCaps = DDSCAPS_TEXTURE;
ddres = lpDD2->GetAvailableVidMem(&ddsCaps,
&dwTotal, &dwFree);
if (FAILED(ddres))
...
This method only gives a snapshot of the current display memory state. The amount of free display memory is subject to change as surfaces are created and released. Therefore, the free memory value should only be used as a rough guide. In addition, a particular display adapter card may make no distinction between two different memory types. For example, it may use the same portion of display memory to store z-buffers and textures. Hence, allocating one type of surface (for example, a z-buffer) may affect the amount of display memory available for another type of surface (for example, textures). Therefore, it is best to first allocate an application's fixed resources (such as front, back and z-buffers) before determining how much memory is available for dynamic use (such as texture mapping).
To ensure COM compliance, this method is not a member of the IDirectDraw interface, but is part of the IDirectDraw2 interface. To use this method, you must first query for the IDirectDraw2 interface. For more information, see IDirectDraw2 Interface.