gpt4 book ai didi

ios - libdispatch(apple-open-source)中的这段代码是什么意思?

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:20:18 25 4
gpt4 key购买 nike

我很难理解下面的代码:

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 func 在 struct 中?谁能帮我学习这些代码?这是 code address

最佳答案

注意 .cpp 扩展名。这是 C++代码。

  1. operator ... = delete 语法表明应该禁止此运算符,如果您尝试使用它,则会生成编译器警告。

  2. 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com