[英]How memory is allocated for Stack and Queue in java
We know ArrayList uses dynamic array to store data.我们知道 ArrayList 使用动态数组来存储数据。 LinkedList uses linked list to store data.
LinkedList 使用链表来存储数据。 So, for both these case we know how it works when there is a new element added or deleted(Memory wise).
因此,对于这两种情况,我们都知道添加或删除新元素时它是如何工作的(内存方面)。 Now similarly, how memory is allocated for a Stack or Queue in java.
现在类似地,如何为 java 中的堆栈或队列分配 memory。 What happens, at Memory level, when I add/delete element to/from Stack or Queue.
当我在堆栈或队列中添加/删除元素时,在 Memory 级别会发生什么。
Well, Queue
is an interface, so not much to say about that.好吧,
Queue
是一个接口,所以不多说。 There's a lot of implementations and different behaviours.有很多实现和不同的行为。 Anyway, for instance,
ArrayBlockingQueue
has a memory allocation similar to ArrayList
.无论如何,例如,
ArrayBlockingQueue
具有类似于ArrayList
的 memory 分配。 Anyway, there are two major groups (bounded and unbounded) but it will really depend on the implementation you choose.无论如何,有两个主要组(有界和无界),但这实际上取决于您选择的实现。
About Stack
, the memory allocation is also pretty similar to ArrayList
as it's a subclass of Vector
and this is backed by an array.关于
Stack
, memory 分配也与ArrayList
非常相似,因为它是Vector
的子类,并且由数组支持。
java.util.Stack
is a subclass of java.util.Vector
which is nothing but an array. java.util.Stack
是java.util.Vector
的子类,它只是一个数组。 Now java.util.Queue
is an interface and has various implementations which are divided into two primary categories:现在
java.util.Queue
是一个接口,并具有各种实现,分为两大类:
ArrayBlockingQueue
ArrayBlockingQueue
LinkedBlockingQueue
LinkedBlockingQueue
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.