我很难理解以下代码:
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; 是什么以及为什么 struct 中的 inline 函数?谁能帮我学习这些代码?这里是 code address
Best Answer-推荐答案 strong>
注意 .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 .
关于ios - libdispatch(apple-open-source)中的这段代码是什么意思?,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/54667143/
|