Is it acceptable not to deallocate memory(不释放内存是否可以接受)
问题描述
我正在处理一个应该从命令行使用以下语法的项目:
I'm working on a project that is supposed to be used from the command line with the following syntax:
program-name input-file
程序应该处理输入,计算一些东西并在标准输出上输出结果.
The program is supposed to process the input, compute some stuff and spit out results on stdout.
我选择的语言是 C++,有几个原因我不愿意争论.计算阶段将是高度象征性的(想想编译器),并将使用非常复杂的动态分配的数据结构.特别是,它不适合 RAII 风格的编程.
My language of choice is C++ for several reasons I'm not willing to debate. The computation phase will be highly symbolic (think compiler) and will use pretty complex dynamically allocated data structures. In particular, it's not amenable to RAII style programming.
我想知道忘记释放内存是否可以接受,因为我希望整个计算消耗的内存少于可用内存,并且操作系统可以在程序完成后一步自由地回收所有内存(假设程序在几秒钟内终止).您对此有何看法?
I'm wondering if it is acceptable to forget about freeing memory, given that I expect the entire computation to consume less than the available memory and that the OS is free to reclaim all the memory in one step after the program finishes (assume program terminates in seconds). What are your feeling about this?
作为备用计划,如果我的项目需要作为服务器或交互运行,我想我总是可以将垃圾收集器重新安装到源代码中.有没有人有使用 C++ 垃圾收集器的经验?他们工作得好吗?
As a backup plan, if ever my project will require to run as a server or interactively, I figured that I can always refit a garbage collector into the source code. Does anyone have experience using garbage collectors for C++? Do they work well?
推荐答案
在问题描述的具体情况下应该不会造成任何问题.
It shouldn't cause any problems in the specific situation described the question.
然而,这并不完全正常.静态分析工具会抱怨它.最重要的是,它会养成坏习惯.
However, it's not exactly normal. Static analysis tools will complain about it. Most importantly, it builds bad habits.
这篇关于不释放内存是否可以接受的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:不释放内存是否可以接受


基础教程推荐
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 初始化列表*参数*评估顺序 2021-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- CString 到 char* 2021-01-01