ali schreef:
> ok i understand that using Vector of Vectors will need more memory but
> will it make the application slower than using Array of Vectors ??!!!
It will, yes. A Vector essentially wraps around an array, so any
operations on a Vector will endure at least one extra (synchronized: cf
infra) indirection when compared to an array. Some considerations:
- Vector's are only really useful when you do not know in advance the
length of your array. If the length is fixed: use an array (certainly
when performance is an issue)
- If all dimensions are known in advance, why not use an array of arrays?
- Only use the Vector class if you need synchronization. If your
application is a single-threaded class, you are better of using an
ArrayList (even if you need the synchronization overhead, it is probably
wiser to use Collections.synchronizedList on an ArrayList)
Cheers,
Peter
ali - 26 Oct 2006 02:35 GMT
> ali schreef:
> > ok i understand that using Vector of Vectors will need more memory but
[quoted text clipped - 15 lines]
> Cheers,
> Peter
Thanks a lot Peter for your information and advice
the reason why i am using Vector is that i dont know the size of array
in advance
well i know at maximum it could be [256*256] <--- this implies to the
outer array and the inner array as well, but i am afraid of holding an
array that huge
Wibble - 28 Oct 2006 03:35 GMT
>> ali schreef:
>>> ok i understand that using Vector of Vectors will need more memory but
[quoted text clipped - 23 lines]
> outer array and the inner array as well, but i am afraid of holding an
> array that huge
Thats tiny.
Chris Uppal - 28 Oct 2006 12:15 GMT
> > the reason why i am using Vector is that i dont know the size of array
> > in advance
[quoted text clipped - 3 lines]
> >
> Thats tiny.
64K is indeed a small size for an array -- but not when you have on the order
of 64K of them !
To the OP: the structure you use for the outer container won't make very much
difference to the speed of your app, and will make no significant difference to
the space it takes. However it might be worthwhile considering using raw
arrays for the inner lists. Also, if the elements of the inner arrays are
numbers -- ints, floats, etc -- which I rather suspect they may be, then you
/MUST NOT/ use ArrayLists or Vectors to hold them or your space consumption
will go through the roof.
-- chris