I am trying to use a piece of java code (not written by me), which has following declaration : private int _q .... _q = new int; Now, i am planning to increase the size of the int array to something like (to solve another problem...huh..) : _q = new int; //will the memory be allocated immediately ? But i fear that, doing this may cause lot of memory to be allocated to the int array. How much, how does one calculate this ? Is it utterly foolish to create a int array that large in size ? Or is this ok. Awaiting response Thanks..
posted 12 years ago
>_q = new int; //will the memory be allocated immediately ? yes. 32768 32-bit (4 byte) ints will be created, all set to the integral default of 0. so if you like to work in kb, that would be 32768*4/1024 = 128k. (my math is notoriously bad so its worth checking this ) note that you aren't increasing the array size - arrays are immutable, like spock's facial expressions. you are changing the reference _q to point to a new array, leaving the other to be (probably) garbage collected. maybe you could give some context - why do you need 32k integers? that would help the "best way to go about it" debate to get started. hth peter