标准库头文件 <new>
来自cppreference.com
此头文件是动态内存管理库的一部分,特别提供低层内存管理特性。
类 | |
内存分配失败时抛出的异常 (类) | |
(C++11) |
在分配有非法长度的数组时抛出的异常 (类) |
用于选择不抛出分配函数的标签类型 (类) | |
(C++17) |
用于向带对齐分配及解分配函数传递对齐值的类型 (枚举) |
(C++20) |
用于鉴别 operator delete 的销毁删除重载的标签类型 (类) |
类型 | |
new 处理函数的函数指针类型 (typedef) | |
常量 | |
用于选择不抛出分配函数的 nothrow_t 类型对象 (常量) | |
避免假共享的最小偏移 促使真共享的最大偏移 (常量) | |
函数 | |
分配函数 (函数) | |
解分配函数 (函数) | |
(C++11) |
获得当前的 new 处理函数 (函数) |
注册一个 new 处理函数 (函数) | |
(C++17) |
指针优化屏障 (函数模板) |
概要
namespace std { // 存储分配错误 class bad_alloc; class bad_array_new_length; struct destroying_delete_t { explicit destroying_delete_t() = default; }; inline constexpr destroying_delete_t destroying_delete{}; // 全局 operator new 控制 enum class align_val_t : size_t {}; struct nothrow_t { explicit nothrow_t() = default; }; extern const nothrow_t nothrow; using new_handler = void (*)(); new_handler get_new_handler() noexcept; new_handler set_new_handler(new_handler new_p) noexcept; // 指针优化屏障 template<class T> [[nodiscard]] constexpr T* launder(T* p) noexcept; // 硬件干涉大小 inline constexpr size_t hardware_destructive_interference_size = /* 由实现定义 */; inline constexpr size_t hardware_constructive_interference_size = /* 由实现定义 */; } // 存储分配与解分配 [[nodiscard]] void* operator new(std::size_t size); [[nodiscard]] void* operator new(std::size_t size, std::align_val_t alignment); [[nodiscard]] void* operator new(std::size_t size, const std::nothrow_t&) noexcept; [[nodiscard]] void* operator new(std::size_t size, std::align_val_t alignment, const std::nothrow_t&) noexcept; void operator delete(void* ptr) noexcept; void operator delete(void* ptr, std::size_t size) noexcept; void operator delete(void* ptr, std::align_val_t alignment) noexcept; void operator delete(void* ptr, std::size_t size, std::align_val_t alignment) noexcept; void operator delete(void* ptr, const std::nothrow_t&) noexcept; void operator delete(void* ptr, std::align_val_t alignment, const std::nothrow_t&) noexcept; [[nodiscard]] void* operator new[](std::size_t size); [[nodiscard]] void* operator new[](std::size_t size, std::align_val_t alignment); [[nodiscard]] void* operator new[](std::size_t size, const std::nothrow_t&) noexcept; [[nodiscard]] void* operator new[](std::size_t size, std::align_val_t alignment, const std::nothrow_t&) noexcept; void operator delete[](void* ptr) noexcept; void operator delete[](void* ptr, std::size_t size) noexcept; void operator delete[](void* ptr, std::align_val_t alignment) noexcept; void operator delete[](void* ptr, std::size_t size, std::align_val_t alignment) noexcept; void operator delete[](void* ptr, const std::nothrow_t&) noexcept; void operator delete[](void* ptr, std::align_val_t alignment, const std::nothrow_t&) noexcept; [[nodiscard]] void* operator new (std::size_t size, void* ptr) noexcept; [[nodiscard]] void* operator new[](std::size_t size, void* ptr) noexcept; void operator delete (void* ptr, void*) noexcept; void operator delete[](void* ptr, void*) noexcept;