03-23-2009 02:58 AM
http://na.blackberry.com/eng/deliverables/5827/Avo
Is this advice encouraging us to shift away from using Vectors/Hashtables ?
How else would you step throught a Vector ?
Regards,
G
Solved! Go to Solution.
03-23-2009 04:44 AM
03-23-2009 07:25 AM
Not sure what the speed is for vector.elementAt() but normally I've been trying to convert
vectors to arrays once their sizes are known. Only time hashes come up is when you need
fast access and can tolerate some wasted memory.I'm not sure if there are any tricks to
enumerating the entries but if you have to go check each one then it will take some time...
I've only used enumeration with these for
debugging and some housekeeping code but if you determine you need to enumerate
a lot you may want to consider a different approach. If you have static data RIM offers
some array sorting facilities to let you put everything into an array and even index if for searching.
BTW, anyone know about memory caching on the RIM phones- does locality loss hurt much?
I've given up caring in java in most cases since I can't control memory but it is mentioned here.
http://en.wikipedia.org/wiki/Hash_table
I guess I hadn't worried much about hash key generation since I hope it is implemented in native
code but compared to a native binary search you would worry.
I guess if you need enumeration and think you need a hash table, consider a linked list approach such
that each table entry has a pointer to some prior and next item as then any item gives you an
automatic enumeration.
03-23-2009 10:40 PM
@simon,
On the other hand i implemented the "real" (j2se) enumeration interface in some classes as vector is not always the most convinient choice.
Just curious, when is Vector not a convenient choice ? A Vector is basically a dynamically size-adjusting list.
I'm spoiled by things like Android, which provides you so much power.
Having to reinvent all these things makes development a bit slower.
And BB does not have proper MVC either.
03-23-2009 10:50 PM
..convert vectors to arrays once their sizes are known.
That's a good practice.
BB provides the IntHashtable and IntIntHashtable which are alleged to be more memory efficient than the vanilla one.
+1 on the linked list approach.
03-24-2009 10:39 PM - edited 03-24-2009 10:40 PM
This is the best practice to follow:
04-09-2009 03:38 PM - edited 04-09-2009 03:39 PM
gibli can you elaborate on your second point? Are you saying that net.rim.device.api.collection.List is more efficient than java.util.Vector?
Thanks.