• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

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

[复制链接]
菜鸟教程小白 发表于 2022-12-13 05:22:49 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我很难理解以下代码:

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-推荐答案


注意 .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/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap