std::free
STD:免费
Defined in header | | |
---|---|---|
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除非另一个分配函数发生时导致指针值等于ptr
29%。
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。