datastructure performance

A

ali

Hi there

well i need to know something about how java data structures affects
performance

i need to deal with a huge Vector of element and each element is
another big Vector , someone have advised me to use array of vectors
instead of what i am doing now which is vector of vectors.

ok i understand that using Vector of Vectors will need more memory but
will it make the application slower than using Array of Vectors ??!!!
 
P

Peter Van Weert

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
 
A

ali

Peter said:
ali schreef:
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

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
 
W

Wibble

ali said:
Peter said:
ali schreef:
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

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
Thats tiny.
 
C

Chris Uppal

Wibble said:
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
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top