在C ++程序终止时返回内存 [英] Return of memory at the termination of a C++ program

查看:136
本文介绍了在C ++程序终止时返回内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当C ++程序终止时,在运行期间使用的RAM被清除并返回到系统,正确?



问题1)
此内存是否由C ++语言特性或计算机硬件本身管理?



问题2)
如果在Unix终端中使用 ctrl + Z 终止运行,内存是否有效/安全地返回?

解决方案


当C ++程序终止时,运行期间使用的RAM被清除,系统,是否正确?


正确。问题1)此内存是否由C ++返回托管的 。 语言功能或计算机硬件本身?


>通过操作系统(如果我正确地理解了问题)。在返回到操作系统之前,内存由进程管理;在低级,这意味着,由各种语言功能,如分配 - 释放机制,构造函数,析构函数,问题2)内存是否有效/安全地返回,如果我终止一个运行使用ctrl + Z在Unix终端?


Ctrl + Z暂停它不终止它。因此,只要进程未终止,内存不会返回到操作系统。



在linux中,Ctrl + C终止进程,然后内存返回操作系统。


When a C++ program terminates, the RAM used during the run gets cleaned and is returned to the system, correct?

Question 1) Is this memory returned managed by C++ language features or by the computer hardware itself?

Question 2) Does the memory get returned efficiently/safely, if I terminate a run using ctrl+Z in Unix terminal?

解决方案

When a C++ program terminates, the RAM used during the run gets cleaned and is returned to the system, correct?

Correct. By System, I hope you mean, Operating System.

Question 1) Is this memory returned managed by C++ language features or by the computer hardware itself?

The returned memory is managed by the operating system (if I correctly understand the question). And before returning to the OS, the memory is managed by the process; in low-level, which means, managed by various language features, such as allocation- deallocation mechanism, constructors, destructors, RAII, etc.

Question 2) Does the memory get returned efficiently/safely, if I terminate a run using ctrl+Z in Unix terminal?

Ctrl+Z suspends the process. It doesn't terminate it. So the memory doesn't get returned to the OS as long as the process is not terminated.

In linux, Ctrl+C terminates the process, then the memory returns to the OS.

这篇关于在C ++程序终止时返回内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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