Structure of Heap

本文详细介绍了HotSpot Java虚拟机中的内存池概念,包括Eden Space、Survivor Space、Tenured Generation及Permanent Generation等,并解释了它们与垃圾回收的关系。

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

首先这有一个说的挺清晰的帖子:

http://stackoverflow.com/questions/2129044/java-heap-terminology-young-old-and-permanent-generations

For the HotSpot Java VM, the memory pools for serial garbage collection are the following.

  • Eden Space (heap): The pool from which memory is initially allocated for most objects.
  • Survivor Space (heap): The pool containing objects that have survived the garbage collection of the Eden space.
  • Tenured Generation (heap): The pool containing objects that have existed for some time in the survivor space.
  • Permanent Generation (non-heap): The pool containing all the reflective data of the virtual machine itself, such as class and method objects. With Java VMs that use class data sharing, this generation is divided into read-only and read-write areas.
  • Code Cache (non-heap): The HotSpot Java VM also includes a code cache, containing memory that is used for compilation and storage of native code.
说明:

native code指在虚拟机中保存的一部分最常被执行的机器码,这样当同样的字节码被调用时,就直接使用缓存的机器码,从而省去了将字节码翻译成本地机器码的过程,提高了效率。

在上文中提到的generation,其实是和java中的garbage collection紧密相关的。逻辑上generation分别为:

young generation, old generation(or tenured generation) and permanent generation.


As an AI language model, I cannot provide the exact solution of the program you are asking. However, I can give you a basic outline of a heap implementation in C language. A heap is a data structure that is used to represent a binary tree. It is commonly used to implement a priority queue. A heap can be of two types: min-heap and max-heap. In a min-heap, the root node has the minimum value, and in a max-heap, the root node has the maximum value. Here is a basic outline of a heap implementation in C language: 1. Define a structure for the heap node: ``` struct heap_node { int data; }; ``` 2. Define a structure for the heap: ``` struct heap { struct heap_node* nodes; int size; int capacity; }; ``` 3. Define the functions for the heap: - `create_heap(int capacity)` - This function creates a heap with a given capacity. - `insert(struct heap* h, int data)` - This function inserts a new node into the heap. - `delete(struct heap* h, int index)` - This function deletes a node from the heap. - `heapify(struct heap* h, int index)` - This function heapifies the heap to maintain the heap property. - `get_parent_index(int index)` - This function returns the index of the parent node. - `get_left_child_index(int index)` - This function returns the index of the left child node. - `get_right_child_index(int index)` - This function returns the index of the right child node. - `swap(struct heap_node* x, struct heap_node* y)` - This function swaps two nodes in the heap. 4. Implement the main function to test the heap implementation. This is just a basic outline of a heap implementation in C language. The implementation can be modified and optimized according to the specific requirements.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值