IDirectDraw4::GetAvailableVidMem

This 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( 
  LPDDSCAPS2 lpDDSCaps2, 
  LPDWORD lpdwTotal, 
  LPDWORD lpdwFree
);

Parameters

  • lpDDSCaps2
    Address of a DDSCAPS2 structure that indicates the hardware capabilities of the proposed surface.
  • lpdwTotal
    Address of a variable that will be filled with the total amount of display memory available, in bytes. The value retrieved reflects the total video memory, less the video memory required for the primary surface and any private caches the display driver reserves.
  • lpdwFree
    Address of a variable that will be filled with the amount of display memory currently free that can be allocated for a surface that matches the capabilities specified by the structure at lpDDSCaps2.

Return Values

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.

Remarks

The following C++ example demonstrates using IDirectDraw4::GetAvailableVidMem to determine both the total and free display memory available for offscreen map surfaces.

// For this example, the lpDD variable is a valid 
// pointer to an IDirectDraw interface.
LPDIRECTDRAW4 lpDD4;
DDSCAPS2      ddsCaps2; 
DWORD         dwTotal; 
DWORD         dwFree;
HRESULT       hr; 
 
hr = lpDD->QueryInterface(IID_IDirectDraw4, &lpDD4); 
if (FAILED(hr))
    return hr; 
 
// Initialize the structure.
ZeroMemory(&ddsCaps2, sizeof(ddsCaps2));
 
ddsCaps2.dwCaps = DDSCAPS_OFFSCREENPLAIN; 
hr = lpDD4->GetAvailableVidMem(&ddsCaps2, &dwTotal, &dwFree); 
if (FAILED(hr))
    return hr;

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). For best results, 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.

Requirements

OS Versions: Windows CE 2.12 and later. Version 2.12 requires DXPAK 1.0 or later.
Header: Ddraw.h.
Link Library: Ddraw.lib.

 Last updated on Thursday, April 08, 2004

© 1992-2003 Microsoft Corporation. All rights reserved.