libdispatch(apple-open-source)中的这段代码是什么意思?
what's meaning of this code from the libdispatch (apple-open-source)?
我很难理解以下代码:
struct dispatch_block_private_data_s {
DISPATCH_BLOCK_PRIVATE_DATA_HEADER();
static void* operator new(size_t) = delete;
static void* operator new [] (size_t) = delete;
explicit inline DISPATCH_ALWAYS_INLINE dispatch_block_private_data_s(
dispatch_block_flags_t flags, voucher_t voucher,
pthread_priority_t priority, dispatch_block_t block) noexcept :
dbpd_magic(), dbpd_flags(flags), dbpd_atomic_flags(),
dbpd_performed(), dbpd_priority(priority), dbpd_voucher(voucher),
dbpd_block(block), dbpd_group(), dbpd_queue(), dbpd_thread()
{
// stack structure constructor, no releases on destruction
_dispatch_block_private_data_debug("create, block: %p", dbpd_block);
}
};
static void* operator new(size_t) = delete;
是什么,为什么 inline
在 struct
中起作用?谁能帮我学习这些代码?这是 code address
注意 .cpp
扩展名。这是 C++ 代码。
operator ... = delete
语法表明应该禁止使用此运算符,如果您尝试使用它会生成编译器警告。
inline
限定符是一种性能优化。引用自The C++ Programming Language:
The inline
specifier is a hint to the compiler that it should attempt to generate code for a call of [the function] inline rather than laying down the code for the function once and then calling through the usual function call mechanism.
如果(a)一个函数很小;并且(b)性能是最重要的,您可以使用 inline
限定符,这样编译器将有效地在您使用函数的任何地方插入函数代码,而不是将其保存为函数并正常调用它将。这节省了调用函数的适度开销。
如果您在理解 C++ 方面需要帮助,我建议您查看 these resources。
我很难理解以下代码:
struct dispatch_block_private_data_s {
DISPATCH_BLOCK_PRIVATE_DATA_HEADER();
static void* operator new(size_t) = delete;
static void* operator new [] (size_t) = delete;
explicit inline DISPATCH_ALWAYS_INLINE dispatch_block_private_data_s(
dispatch_block_flags_t flags, voucher_t voucher,
pthread_priority_t priority, dispatch_block_t block) noexcept :
dbpd_magic(), dbpd_flags(flags), dbpd_atomic_flags(),
dbpd_performed(), dbpd_priority(priority), dbpd_voucher(voucher),
dbpd_block(block), dbpd_group(), dbpd_queue(), dbpd_thread()
{
// stack structure constructor, no releases on destruction
_dispatch_block_private_data_debug("create, block: %p", dbpd_block);
}
};
static void* operator new(size_t) = delete;
是什么,为什么 inline
在 struct
中起作用?谁能帮我学习这些代码?这是 code address
注意 .cpp
扩展名。这是 C++ 代码。
operator ... = delete
语法表明应该禁止使用此运算符,如果您尝试使用它会生成编译器警告。inline
限定符是一种性能优化。引用自The C++ Programming Language:The
inline
specifier is a hint to the compiler that it should attempt to generate code for a call of [the function] inline rather than laying down the code for the function once and then calling through the usual function call mechanism.如果(a)一个函数很小;并且(b)性能是最重要的,您可以使用
inline
限定符,这样编译器将有效地在您使用函数的任何地方插入函数代码,而不是将其保存为函数并正常调用它将。这节省了调用函数的适度开销。
如果您在理解 C++ 方面需要帮助,我建议您查看 these resources。