The IDirectDraw2::GetAvailableVidMem method retrieves the total amount of display memory available and the amount of display memory currently free for a given type of surface.
HRESULT GetAvailableVidMem(
LPDDSCAPS lpDDSCaps,
LPDWORD lpdwTotal,
LPDWORD lpdwFree
);
If the method succeeds, the return value is DD_OK.
If the method fails, the return value may be one of the following error values:
DDERR_INVALIDCAPS |
DDERR_INVALIDOBJECT |
DDERR_INVALIDPARAMS |
DDERR_NODIRECTDRAWHW |
If NULL is passed to either lpdwTotal or lpdwFree, the value for that parameter is not returned.
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 provides only 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, you should use the free memory value only as an approximation. In addition, a particular display adapter card may make no distinction between two different memory types. For example, the adapter might use the same portion of display memory to store z-buffers and textures. So, allocating one type of surface (for example, a z-buffer) can 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 and back buffers , and z-buffers) before determining how much memory is available for dynamic use (such as texture mapping).
This method was not implemented in the IDirectDraw interface.
Windows NT: Use version 4.0 or later.
Windows: Use Windows 95 or later. Available as a redistributable for Windows 95.
Windows CE: Unsupported.
Header: Declared in ddraw.h.
Import Library: Use ddraw.lib.