简体   繁体   English

我们如何知道要设置多少堆?

[英]How do we know how big to set the Heap?

I'm trying to convert Java to an intermediate language and am in the process of figuring out how the intermediate language works. 我正在尝试将Java转换为中间语言,并且正在弄清楚中间语言的工作方式。

I have the original Java code: http://cs.ucla.edu/classes/spring11/cs132/cs132/mj/Factorial.java 我有原始的Java代码: http : //cs.ucla.edu/classes/spring11/cs132/cs132/mj/Factorial.java

And I have the Intermediate Code representation (VAPOR): http://cs.ucla.edu/classes/spring11/cs132/kannan/vapor-examples/Factorial.vapor 而且我有中级代码表示形式(VAPOR): http : //cs.ucla.edu/classes/spring11/cs132/kannan/vapor-examples/Factorial.vapor

Here's another set: in Java: http://cs.ucla.edu/classes/spring11/cs132/cs132/mj/BubbleSort.java 这是另一组:在Java中: http : //cs.ucla.edu/classes/spring11/cs132/cs132/mj/BubbleSort.java

In VAPOR: http://cs.ucla.edu/classes/spring11/cs132/kannan/vapor-examples/BubbleSort.vapor 在VAPOR中: http : //cs.ucla.edu/classes/spring11/cs132/kannan/vapor-examples/BubbleSort.vapor

My question is, all of the VAPOR code has t.0 = HeapAllocZ(x) (where x is an int ). 我的问题是,所有的VAPOR代码都具有t.0 = HeapAllocZ(x) (其中xint )。 I'm wondering how the converter determines the heap size needs to be size x . 我想知道转换器如何确定堆大小需要为x In Factorial.vapor , it's set to 4 . Factorial.vapor ,将其设置为4 In BubbleSort.vapor , it's set to 12 . BubbleSort.vapor ,将其设置为12

Thanks! 谢谢!

It looks like the HeapAlloc is based on the size of the structure you are creating (assuming 4 and 12 are byte values). 看起来HeapAlloc是基于要创建的结构的大小(假定412是字节值)。 I would think that looking at the variables your data structure uses, and counting the number of bytes those variables sum to would give you the number being allocated. 我认为查看数据结构使用的变量,并计算这些变量求和的字节数将为您分配数量。

If you notice, the Java version of Factorial has no data members. 如果您注意到,Java版本的阶乘没有数据成员。 The Java version of BubbleSort has two 4-byte ints (8 bytes total). Java版本的BubbleSort具有两个4字节的整数(总共8个字节)。

Presumably the "overhead" of an object is 4 bytes (the size of a pointer to the class object). 假定对象的“开销”是4个字节(指向类对象的指针的大小)。

So Factorial has an object size of 4 and BubbleSort has an object size of 12. 因此,阶乘的对象大小为4,而BubbleSort的对象大小为12。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM