Comments on: Implement a Stack Using an Array https://www.happycoders.eu/algorithms/implement-stack-using-array/ Wed, 27 Nov 2024 13:36:07 +0000 hourly 1 By: Siv https://www.happycoders.eu/algorithms/implement-stack-using-array/#comment-18643 Fri, 21 Jul 2023 20:43:49 +0000 https://www.happycoders.eu/books/stack-implementieren-array/#comment-18643 In reply to Sven Woltmann.

Thanks for the clarity

]]>
By: Sven Woltmann https://www.happycoders.eu/algorithms/implement-stack-using-array/#comment-18626 Wed, 19 Jul 2023 07:42:22 +0000 https://www.happycoders.eu/books/stack-implementieren-array/#comment-18626 In reply to Siv.

Hi Siv,

different JVMs have different limits for array sizes. With OpenJDK 21, for example, the maximum array size is Integer.MAX_VALUE - 2. If you try to create a larger array, you will get the following error:

Exception in thread "main" java.lang.OutOfMemoryError: Requested array size exceeds VM limit

I used a more conservative limit to be on the safe side. The JDK also uses Integer.MAX_VALUE - 8 for array-based data structures (see https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/jdk/internal/util/ArraysSupport.java#L692).

Best wishes
Sven

]]>
By: Siv https://www.happycoders.eu/algorithms/implement-stack-using-array/#comment-18625 Wed, 19 Jul 2023 02:11:43 +0000 https://www.happycoders.eu/books/stack-implementieren-array/#comment-18625 Why we are initializing MAX_SIZE as Integer.MAX_VALUE - 8 instead of Integer.MAX_VALUE? Any reason?

]]>