简单的内存分配和免费问题 [英] the simple memory alloc and free problem

查看:61
本文介绍了简单的内存分配和免费问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

< pre>  //   allloc the memory  
int * lastBuffer = new int [1·;< m_exp];

// 通过 std :: free 免费提供回忆( )
std :: free (lastBuffer);





免费方法还行吗?如果没有,问题是什么?



或更多信息?

解决方案

永远不会与alloaction不匹配对



new< - >删除

alloc< - >免费



制作一张海报并挂在床上; - )


如果您使用 malloc 分配内存,使用免费取消分配。

如果你使用 new 分配内存,使用删除取消分配。

切勿将它们混合在一起。



阅读该人自己要说的内容 - http://www.stroustrup.com/bs_faq2。 html#malloc [ ^ ]

<pre>//allloc the memory
int * lastBuffer = new int[1<<m_exp];

//free the memroy by std::free()
std::free(lastBuffer );



the free method is OK? if not ,what's the problem?

Or more info?

解决方案

NEVER EVER mismatch the "alloaction pairs"

new <-> delete
alloc <-> free

Make a poster and hang it above your bed ;-)


If you use malloc to allocate memory, use free to deallocate it.
If you use new to allocate memory, use delete to deallocate it.
Never mix them together.

Read what the man himself has to say - http://www.stroustrup.com/bs_faq2.html#malloc[^]


这篇关于简单的内存分配和免费问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆