[英]How to release BYTE memory?
Quick question: do I have to / how do I release memory from this allocation of memory?快速提问:我是否必须/如何从 memory 的分配中释放 memory?
unsigned char *uString = new unsigned char[4096]();
And if I have to, would I do it like this?如果我必须这样做,我会这样做吗?
free(uString); delete[] uString;
You use the free
function when you allocate memory with the C functions like malloc
calloc
and more.当您分配
free
与 C 函数如malloc
和calloc
In c++ you use the operators new
and delete
(Also thier array friends new[]
and delete[]
).在 c++ 中,您使用运算符
new
和delete
(还有他们的数组朋友new[]
和delete[]
)。
When you want to delete object created with the operator new[]
, you call the operator delete[]
.当你想删除用 operator
new[]
创建的 object 时,你调用 operator delete[]
。 For example:例如:
int main(void)
{
int[] arr = new int[5];
int* a = new int;
delete[] arr;
delete a;
return 0;
}
And that's all.就这样。 That will also call the destructor an all of that.
这也将调用析构函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.