简体   繁体   English

我执行了以下代码并且我的系统卡住了,但我无法找出背后的原因?

[英]I executed the following code and my system stuck, but I am not able to figure out reason behind it?

#include<stdio.h>
int main(){
    while(1){
        int *a = new int[1000];
    }
}

How the heap is growing here and how the operating system handles it?堆在这里如何增长以及操作系统如何处理它? I do not understand how memory management is handled here.我不明白这里是如何处理 memory 管理的。 I thought that the OS allocates a fixed-size stack and heap?我以为操作系统分配了一个固定大小的堆栈和堆? What is the max amount of heap and stack allocated to the program and how?分配给程序的最大堆和堆栈数量是多少?如何分配?

Int *a = new int[1000] creates an array in new location of memory, and sets pointer to first element of array into variable a. int *a = new int[1000] 在 memory 的新位置创建一个数组,并将指向数组第一个元素的指针设置为变量 a。 (Variable a is an pointer). (变量 a 是一个指针)。 You won't get this problem in java and other languages because they have garbage collector, that delete old array, c++ don't have it, so you need to use delete keyword.在 java 和其他语言中你不会遇到这个问题,因为它们有垃圾收集器,删除旧数组,c++ 没有它,所以你需要使用 delete 关键字。 (Deleting variables and arrays have little bit different syntaxis. Your loop will run until you'r pc run out of ram, read about memory leak in c++ (删除变量和 arrays 的语法略有不同。您的循环将一直运行,直到您的 pc 用完 ram,请阅读 c++ 中的 memory 泄漏

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我的代码不断收到 SIGTSTP 错误,但我无法弄清楚我的代码在哪里越界 - I keep getting SIGTSTP error for my code but I am not able to figure out where is my code going out of bounds 我的程序不断抛出编译错误,我无法弄清为什么会发生该错误 - My program keeps throwing compilation error,I am not able to figure out why the error has occured 这是一个二进制搜索代码,我无法找出问题所在 - it is a binary search code and i m not able to figure out the problem 我用宏执行了以下代码 - I executed following code with macro 在以下代码中执行删除操作时,我无法获得以下代码中返回的正确值。 - While performing the delete operation in the following code, I am not able to get the correct values returned in the following code. 我是C ++的新手,正在努力弄清楚为什么我的代码可以正常运行,但是在运行后仍然返回荒谬的数字 - I am new to C++ and struggling to figure out why my code works perfectly but still returns an absurd number after running 我无法找出这段代码哪里出错了 - I am Not able to find out where this code went wrong 我的最后一个正则表达式不起作用,但是我无法弄清楚为什么 - My last regular expression won't work but i cannot figure out the reason why 这是我被卡住的问题。 在 22 个测试用例中,有 5 个性能测试用例失败了。 如何优化我的代码? - This is a problem where I am stuck. Out of 22 test cases 5 performance test cases are getting failed. How to optimise my code? 我无法弄清楚 the.end function 在这个 cpp 程序中是如何工作的 - i am not able to figure it out how the .end function is working in this cpp program
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM