什么是__builtin_operator_new及其工作方式? [英] What is __builtin_operator_new and how it works?

查看:123
本文介绍了什么是__builtin_operator_new及其工作方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在检查libc ++代码时,我看到ndk分配器 __ allocate 函数正在调用 __ builtin_operator_new ,但找不到它的定义是在libc ++代码中。

While going through libc++ code, I see ndk allocators __allocate function is calling __builtin_operator_new, but I could not found its definition in libc++ code.

根据名字,很明显它是内存分配函数。但是谁来实现呢?它是由clang,gcc之类的编译器定义的吗?在哪里可以找到其定义?

By name it is evident that it is memory allocation function. But who implements it? Is it defined by compiler like clang, gcc? where can I find its definition?

推荐答案

这是一个内在函数,由编译器本身隐式定义(因此称为内置函数) 。它是该语言的文档 lang的扩展部分:

It's an intrinsic, defined implicitly by the compiler itself (hence why it's called a builtin). It's documented on the language extension section for Clang:


__ builtin_operator_new和__builtin_operator_delete

__ builtin_operator_new 就像非放置非类new-expression一样分配内存。就像直接调用普通的非放置 :: operator new 一样,除了它允许某些优化,而C ++标准不允许直接调用 :: operator new (特别是删除新的/删除对并合并分配)。

__builtin_operator_new allocates memory just like a non-placement non-class new-expression. This is exactly like directly calling the normal non-placement ::operator new, except that it allows certain optimizations that the C++ standard does not permit for a direct function call to ::operator new (in particular, removing new / delete pairs and merging allocations).

与之类似, __ builtin_operator_delete 像非类的delete-expression一样释放内存,就像直接调用普通的 :: operator delete 一样。它允许优化。当前仅可使用 __ builtin_operator_delete 的无格式形式。

Likewise, __builtin_operator_delete deallocates memory just like a non-class delete-expression, and is exactly like directly calling the normal ::operator delete, except that it permits optimizations. Only the unsized form of __builtin_operator_delete is currently available.

这些内置函数旨在用于实现 std :: allocator 和其他类似的分配库,仅在C ++中可用。

These builtins are intended for use in the implementation of std::allocator and other similar allocation libraries, and are only available in C++.

这篇关于什么是__builtin_operator_new及其工作方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆