std::free
Defined in header <cstdlib> | | |
|---|---|---|
void free( void* ptr ); | | |
分配以前由std::malloc(),,,std::calloc()或std::realloc()...
如果ptr是一个空指针,函数什么也不做。
如果ptr返回的值不等于std::malloc(),,,std::calloc(),或std::realloc()...
如果ptr已经被取消了,就是,std::free()或std::realloc()已经被调用ptr作为争论而不是呼吁std::malloc(),,,std::calloc()或std::realloc()导致指针等于ptr之后。
如果是在后面,则行为未定义。std::free()返回时,将通过指针进行访问。ptr%28除非另一个分配函数发生时导致指针值等于ptr29%。
The following functions are required to be thread-safe: The library versions of operator new and operator delete User replacement versions of global operator new and operator delete std::calloc, std::malloc, std::realloc, std::aligned_alloc (since C++17) Calls to these functions that allocate or deallocate a particular unit of storage occur in a single total order, and each such deallocation call happens-before the next allocation (if any) in this order. | (since C++11) |
|---|
- 的库版本
operator new和operator delete
- 全局用户替换版本
operator new和operator delete
std::calloc,,,std::malloc,,,std::realloc,,,std::aligned_alloc%28自C++17%29
对分配或释放特定存储单元的这些函数的调用是以单个总顺序进行的,并且每个这样的释放调用都会发生。发生-之前下一次按此顺序分配%28(如果有%29)。
%28自C++11%29
参数
ptr | - | pointer to the memory to deallocate |
|---|
返回值
%280%29
注记
该函数接受%28,并且不使用%29空指针来减少特殊大小写的数量。无论分配成功与否,都可以将分配函数返回的指针传递给free()...
例
二次
#include <cstdlib>
int main()
{
int* p1 = (int*)std::malloc(10*sizeof *p1);
std::free(p1); // every allocated pointer must be freed
int* p2 = (int*)std::calloc(10, sizeof *p2);
int* p3 = (int*)std::realloc(p2, 1000*sizeof *p3);
if(p3) // p3 not null means p2 was freed by std::realloc
std::free(p3);
else // p3 null means p2 was not freed
std::free(p2);
}二次
另见
c免费文件
*。
© cppreference.com在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com

