IntegerArray 960MB内存

本文介绍了一个因将Integer误声明为IntegerArray导致程序占用960MB内存的问题。通过排查发现,IntegerArray实际上是一个长度为$F000000的数组,使用Sizeof(IntegerArray)可得其大小为960MB。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

IntegerArray 960MB内存

 

 

在用delphi编译执行自己写的一个小程序时,以外的发现该程序竟然占用了将近1G的虚拟内存,肯定是哪里的代码有问题,于是一点点的排查代码。结果发现,不小心把自定义记录类型的一个integer类型属性声明成了IntegerArray

 

在delphi的帮助和System等单元代码中都找不到IntegerArray 的相关信息,但是在提示信息中可以看到

 

 

 

IntegerArray 是一个长度为$F000000的整形数组,用Sizeof(IntegerArray)得到的值是1006632960

 

正好是960MB

 

一个小小的错误,960MB的内存就被吃掉了,今后一定要注意啊

Objectives of this Assignment 1. Declare arrays of different types dynamically. 2. Iterate through arrays, processing all of the elements. 3. Write methods with arrays as parameters and return values。 In this assignment you will create your own class and write the methods in it. The class you write is called Main and it has four methods that build arrays and four methods that process arrays. All methods should be public and static. Create a project called P7_1 and a class named Main in a file called Main.java, then follow the instructions below exactly: 1. Write a method named createIntegers that allocates, initializes, and returns an array of integers with n entries from the standard input. The method has no parameters and returns an array of n integers. There are n+1 integers in the input line. The first integer is the number n, and the next n integers are the elements of the array. See the sample input for details. 2.Write a method called sumArray that takes an array of integers as a parameter, and returns an integer equal to the sum of all elements in the array. 3.Add a main method with the usual signature that instantiates the Main class and tests its methods as follows: public static void main(String[] args) { // Create arrays int[] integerArray = createIntegers(); // Test processing System.out.println(sumArray(integerArray)); } NOTE: You must use methods to sovle this problem. HINT: The input codes in createIntegers method should like the following: Scanner in = new Scanner(System.in); int n=in.nextInt(); int[] intArr=new int[n]; int i=0; while(i<n){ intArr[i]=in.nextInt(); i++; } in.close(); return intArr; SAMPLE INPUT: 9 16 21 34 49 55 60 72 83 101 SAMPLE OUTPUT: 491 代码长度限制 16 KB 时间限制 400 ms 内存限制 64 MB 栈限制 8192 KB C (gcc) 1
最新发布
03-10
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值