菜鸟教程小白 发表于 2022-12-13 05:22:49

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


                                            <p><p>我很难理解以下代码:</p>

<p></p>

<pre><code>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(&#34;create, block: %p&#34;, dbpd_block);
    }
};
</code></pre>

<p><code>static void* operator new(size_t) = delete;</code> 是什么以及为什么 <code>struct</code> 中的 <code>inline</code> 函数?谁能帮我学习这些代码?这里是 <a href="https://github.com/apple/swift-corelibs-libdispatch/blob/master/src/block.cpp#L49" rel="noreferrer noopener nofollow">code address</a> </p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>注意 <code>.cpp</code> 扩展名。这是<a href="https://en.m.wikipedia.org/wiki/C%2B%2B" rel="noreferrer noopener nofollow">C++</a>代码。</p>

<ol>
<li><p><code>operator ... = delete</code> 语法表明该运算符应被禁止,如果您尝试使用它,则会生成编译器警告。</p></li>
<li><p><code>inline</code> 限定符是一种性能优化。引用 <a href="https://rads.stackoverflow.com/amzn/click/com/0321563840" rel="noreferrer noopener nofollow" rel="nofollow noreferrer">The C++ Programming Language</a> :</p>

<blockquote>
<p>The <code>inline</code> specifier is a hint to the compiler that it should attempt to generate code for a call of inline rather than laying down the code for the function once and then calling through the usual function call mechanism.</p>
</blockquote>

<p>如果 (a) 一个函数很小; (b) 性能是最重要的问题,您可以使用 <code>inline</code> 限定符,以便编译器有效地将函数的代码插入到您使用它的任何位置,而不是将其保存为函数并调用你通常会的。这节省了调用函数的适度开销。</p></li>
</ol>

<p>如果您在理解 C++ 方面需要帮助,我建议您查看 <a href="https://isocpp.org/get-started" rel="noreferrer noopener nofollow">these resources</a> .</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - libdispatch(apple-open-source)中的这段代码是什么意思?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/54667143/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/54667143/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - libdispatch(apple-open-source)中的这段代码是什么意思?