C++ memory primitive
分配 | 释放 | 类属 | 可否重载 |
malloc() | free() | C函数 | 不可 |
new | free | C++表达式 | 不可 |
::operator new() | ::operator delete() | C++函数 | 可以 |
allocator<T>::allocator() | allocator<T>::deallocator() | C++标准库 | 可自由设计以搭配任何容器 |
::operator new(): 全局函数
使用 :
void *p = ::operator new(512); //分配512字节的内存空间
::operator delete(p)
//与malloc/free用法完全相同,其实底部就是调用了malloc/free