Managing Resources

Resource management is the process in which resources are promoted from system-memory storage to device-accessible storage and discarded from device-accessible storage. The Microsoft Direct3D run time has its own management algorithm based on a least-recently-used priority technique. Direct3D switches to a most-recently-used priority technique when it detects that more resources than can coexist in device-accessible memory are used in a single frame, between Device.BeginScene and EndScene calls.

Use the Managed constant of the Pool enumeration at creation time to specify a managed resource. Managed resources persist through transitions between the lost and operational states of the device. The device can be restored with a call to Reset, and such resources continue to function normally without being reloaded with artwork. However, if the device must be destroyed and re-created, all resources created using Managed must be re-created.

Use the Default flag at creation time to specify that a resource is to be placed in the default pool. Resources in the default pool do not persist through transitions between the lost and operational states of the device. These resources must be released before calling Reset and must then be re-created.

For more information on the lost state of a device, see Lost Devices.

Note that resource management is not supported for all types and usages. For example, objects created with the RenderTarget flag are not supported. In addition, resource management is not recommended for objects whose contents are changing with high frequency. For example, a managed vertex buffer that changes every frame can significantly degrade performance for some hardware. However, this is not a problem for texture resources.