内存分配与新 [英] Memory allocation with new

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

问题描述



我在VC 6.0中编写了一个应用程序。我使用new运算符分配了一些

内存。


1.当我使用new运算符时,是从进程堆分配的内存吗?

如果它是从进程堆分配的,那么当退出

进程时它将被释放。然后我需要在我的应用程序需要更多

内存分配时释放它。


欢迎任何细节,评论和链接。


问候,

Avinash

Hi,
I have written an application in VC 6.0. I have allocated some
memory using new operator.

1.When i use new operator is the memory allocated from process heap?
If it is allocated from process heap then it will be freed when the
process is exited. Then I need to free it only if there are more
memory allocations required by my application.

Any details, comments and links are welcome.

Regards,
Avinash

推荐答案

" Avinash" <平均************* @ infineon.com>在消息中写道

news:cf ************************** @ posting.google.c om ...
"Avinash" <Av*************@infineon.com> wrote in message
news:cf**************************@posting.google.c om...

我在VC 6.0中编写了一个应用程序。我使用new运算符分配了一些
内存。

1.当我使用new运算符时,是从进程堆分配的内存吗?
如果它是从进程堆分配的那么它将会退出
过程后被释放。然后我需要释放它,只有当我的应用程序需要更多的内存分配时。

欢迎任何细节,评论和链接。

问候,< /> Avinash
Hi,
I have written an application in VC 6.0. I have allocated some
memory using new operator.

1.When i use new operator is the memory allocated from process heap?
If it is allocated from process heap then it will be freed when the
process is exited. Then I need to free it only if there are more
memory allocations required by my application.

Any details, comments and links are welcome.

Regards,
Avinash




您好,


AFAIK,new []会在内部调用VirtualAlloc()...

是的,当您的程序存在时,内存将被释放...但是,当不再需要时,分配的内存未分配是一个糟糕的

练习

因为你会让整个系统变得缓慢,更不用说内存泄漏造成的问题......


-

Elias



Hello,

AFAIK, new[] would call VirtualAlloc() internally...
Yes the memory will be freed when your program exists...however it is a bad
practice to leave allocated memory unallocated when not needed anymore
because you will make the whole system slow not to mention problems created
from memory leaks...

--
Elias


Avinash写道:
Avinash wrote:
进程已退出。然后我只有在我的应用程序需要更多内存分配时才需要释放它。
process is exited. Then I need to free it only if there are more
memory allocations required by my application.




创建内存泄漏总是一个坏主意。出于很多原因。

如果你不想小心内存使用,那么C ++就是

错误的语言。

-

gabriel



Creating memory leaks is always a bad idea. For many reasons.

If you would prefer to not be careful about memory usage, then C++ is the
wrong language.

--
gabriel


> 1.当我使用new运算符时,是从进程堆分配的内存吗?


是的。
> 1.When i use new operator is the memory allocated from process heap?

Yes.
如果它是从进程堆分配的那么它退出
过程后将被释放。


是的。

然后我只有在我的应用程序需要更多内存分配时才需要释放它。
If it is allocated from process heap then it will be freed when the
process is exited.
Yes.
Then I need to free it only if there are more
memory allocations required by my application.




是的。



Yes.


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

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