slot 0.0.1
A real time UI render framework
载入中...
搜索中...
未找到
| 枚举
Slang 命名空间参考

class  ComPtr
 

枚举

enum  InitAttach { INIT_ATTACH }
 ComPtr is a simple smart pointer that manages types which implement COM based interfaces. 更多...
 

枚举类型说明

◆ InitAttach

ComPtr is a simple smart pointer that manages types which implement COM based interfaces.

A class that implements a COM, must derive from the IUnknown interface or a type that matches it's layout exactly (such as ISlangUnknown). Trying to use this template with a class that doesn't follow these rules, will lead to undefined behavior. This is a 'strong' pointer type, and will AddRef when a non null pointer is set and Release when the pointer leaves scope. Using 'detach' allows a pointer to be removed from the management of the ComPtr. To set the smart pointer to null, there is the method setNull, or alternatively just assign SLANG_NULL/nullptr.

One edge case using the template is that sometimes you want access as a pointer to a pointer. Sometimes this is to write into the smart pointer, other times to pass as an array. To handle these different behaviors there are the methods readRef and writeRef, which are used instead of the & (ref) operator. For example

Void doSomething(ID3D12Resource** resources, IndexT numResources);
// ...
doSomething(resources[0].readRef(), SLANG_COUNT_OF(resource));
Definition slang-com-ptr.h:50
#define SLANG_COUNT_OF(x)
Definition slang.h:308

A more common scenario writing to the pointer

IUnknown* unk = ...;
Result res = unk->QueryInterface(resource.writeRef());
SLANG_FORCE_INLINE T ** writeRef()
Get ready for writing (nulls contents)
Definition slang-com-ptr.h:146
枚举值
INIT_ATTACH