为什么不可分派句柄在 64 位平台上使用 ptr?
Why do non dispatchable handles use a ptr on 64bit platofrms?
为什么不可分派的句柄并不总是 uint64_t
?为什么在 64 位平台上必须将它们表示为 ptr
?
#if !defined(VK_DEFINE_NON_DISPATCHABLE_HANDLE)
#if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__) ) || defined(_M_X64) || defined(__ia64) || defined (_M_IA64) || defined(__aarch64__) || defined(__powerpc64__)
#define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef struct object##_T *object;
#else
#define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef uint64_t object;
#endif
#endif
规范说
Non-dispatchable handle types are a 64-bit integer type whose meaning is implementation-dependent, and may encode object information directly in the handle rather than acting as a reference to an underlying object. Objects of a non-dispatchable type may not have unique handle values within a type or across types. If handle values are not unique, then destroying one such handle must not cause identical handles of other types to become invalid, and must not cause identical handles of the same type to become invalid if that handle value has been created more times than it has been destroyed.
不一定要用指针,只要是64位的就可以了。
尽可能使用指针的原因是因为 C 和 C++ 没有强类型定义,所以使用指针可以提供一点额外的类型安全性,因为您不能将 VkImageView_T*
分配给 VkImage_T*
.
为什么不可分派的句柄并不总是 uint64_t
?为什么在 64 位平台上必须将它们表示为 ptr
?
#if !defined(VK_DEFINE_NON_DISPATCHABLE_HANDLE)
#if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__) ) || defined(_M_X64) || defined(__ia64) || defined (_M_IA64) || defined(__aarch64__) || defined(__powerpc64__)
#define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef struct object##_T *object;
#else
#define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef uint64_t object;
#endif
#endif
规范说
Non-dispatchable handle types are a 64-bit integer type whose meaning is implementation-dependent, and may encode object information directly in the handle rather than acting as a reference to an underlying object. Objects of a non-dispatchable type may not have unique handle values within a type or across types. If handle values are not unique, then destroying one such handle must not cause identical handles of other types to become invalid, and must not cause identical handles of the same type to become invalid if that handle value has been created more times than it has been destroyed.
不一定要用指针,只要是64位的就可以了。
尽可能使用指针的原因是因为 C 和 C++ 没有强类型定义,所以使用指针可以提供一点额外的类型安全性,因为您不能将 VkImageView_T*
分配给 VkImage_T*
.