Results 1 to 6 of 6
Thread: Arrays memory allocation
- 07-16-2011, 08:14 AM #1
Member
- Join Date
- Jun 2010
- Posts
- 45
- Rep Power
- 0
- 07-16-2011, 08:20 AM #2
Member
- Join Date
- Jul 2011
- Posts
- 43
- Rep Power
- 0
i think array are placed in heap because in stack
The Java system must know, while it is creating the program, the exact lifetime of all the items that are stored on the stack
- 07-16-2011, 08:29 AM #3
Member
- Join Date
- Jun 2010
- Posts
- 45
- Rep Power
- 0
But what if i declare an array irrespective of its type inside the method. Isn't that supposed to go on stack according to java memory doctrines???
- 07-16-2011, 08:39 AM #4
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Where do you think it gets stored and why?
- 07-16-2011, 08:43 AM #5
Member
- Join Date
- Jun 2010
- Posts
- 45
- Rep Power
- 0
May be i guess it all depends on the its definition than on its type. I mean irrespective of primary or reference type it all goes where the user is defining it, inside the method or outside of it. Correct me if am wrong. I need some clear view on this one.
Thank you.
- 07-16-2011, 08:47 AM #6
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
You can think of an array as an object which holds x items
Is somewhat similar toJava Code:public class MyArray{ public int length = 3; int value1; int value2; int value3; }
I must admit this example was found on another post, available here: Java Array is stored in stack or heap? - Stack OverflowJava Code:int[] x = new int[3];
Arrays are stored on the heap.
Similar Threads
-
Arrays memory addresses
By Dayanand in forum New To JavaReplies: 2Last Post: 03-04-2011, 09:17 AM -
JNI Memory Allocation
By Smokin' Caterpillar in forum Advanced JavaReplies: 3Last Post: 09-16-2010, 05:00 PM -
Memory Allocation
By zzpprk in forum Advanced JavaReplies: 2Last Post: 03-16-2010, 01:14 AM -
Array memory allocation
By number5isalive in forum Advanced JavaReplies: 8Last Post: 10-14-2009, 08:04 AM -
Memory Allocation
By kishan in forum New To JavaReplies: 3Last Post: 09-19-2009, 05:47 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks