Good about Java: friendly syntax, memory management[GC can collect unreferenced memory resources], object-oriented features, portability. Stack Stores method invocations, local variables(include object reference, but the object itself is still stored…
Stack and Heap 都是Java用来在RAM中存放数据的地方.Java自动管理堆和栈,用户不能直接的设置堆或栈. Stack:存在于栈中的数据,其大小与生存周期是确定的,栈中的数据可以共享 Heap:可以动态的分配内存大小,无需事先通知编译器生存周期,堆中的数据亦由Java的垃圾回收器不定期回收 Integer a = new Integer(10); new 语句告诉编译器后面的数据在运行时需要动态创建,因此这些数据都存放于堆中 在栈中建立Interger对象的引用变量a Java的…
小结: 1.栈内存 为什么快? Due to this nature, the process of storing and retrieving data from the stack is very fast as there is no lookup required, you just store and retrieve data from the topmost block on it. 堆内存 慢于栈内存 ,但存储空间动态,使用指针访问 Heap is used for dynam…
[215] Kth Largest Element in an Array [Medium] 给个无序数组,返回第K大的数字. 方法1. 直接使用优先队列 priority_queue class Solution { public: int findKthLargest(vector<int>& nums, int k) { priority_queue<int> pq; // priority queue 实现一个大根堆 ; i < nums.size(); ++…