Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2006

Tip: Looking for answers? Try searching our database.

datastructure performance

Thread view: 
ali - 25 Oct 2006 19:39 GMT
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 ??!!!
Peter Van Weert - 25 Oct 2006 20:40 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.