04-21-2009 02:05 AM
I am very new for the blackberry application and have started a few days ago.
This is a query about performance of the 'net.rim.device.api.util.IntVector' class provided by Rim APIs.
I am interested in using it since I have some strings (having numeric values), which is to be read at run time and to be stored in an array of ints.
Now since I am not aware of how many strings can be there so I can't preinitialize the array, SoI was trying to store these string first into a vector, then initalize array to the size of the vector and than copy that vector in to array.
But here comes problem with the java.util.vector, it stores primitives type as Wrapper objects. and I could not find any method to convert an array of Wrapper (Integer) type to array of primitive(int) type.
Then, I found the class IntVector while I was looking into RIM APIs. and I used it.
But I want to be sure for the performance of this class.
So does anyone have any ideas about this class.
Thanks for your ideas and comments in advance.
Solved! Go to Solution.
04-21-2009 06:59 AM
I guess you could step through it in the debugger and get some idea of how it is implemented or just empirically
test it on a phone. Normally, I assume things like this are implemented in native code and should be faster but
sure it could just have java code to make an Integer, LOL. If you run tests, it wouldn't be unreasonable to
try building array blocks and linking them together yourself and then finally create your single array when you
have all your input if this is such a big performance issue. It probably isn't too hard to code a few examples
and time them on a few real phones. I've tried to go to arrays or trees/linked lists but when I need to
load I usually just code a temporary vector. Often people ignore initialization code performance but it
can add up.
04-22-2009 05:26 AM
Thanks for suggestion,
I did the same and found following:
1. IntVector is similar to vector class with differences it is used to hold primitives int only and the operations can be made on these int.
2. Also IntVector is not thread safe according to APIs (See at following link) :
3. The approach being used is to have an array of 10 int elements, then increase this capacity according to capacityIncrement field (by deafault each time it doubles the size)
4. As par performance for me it seems that it has similar performance (memory + processing) overhead as the Vector class.
This class is useful for me because I want a vector which can dynamically contain the primitive ints and then I can copy its elements in to an int array.
If anybody is facing similar issue, he can use this.
But do not use getArray() method to retrieve elements into an array from the instance of this class.
Because in this method array is not trimmed and the array with extra elements(capacity of vector) will be added in this array. So instead of that try to use IntVector.copyInto(int) metho, by creating an array of vector size.
04-22-2009 07:22 AM
Well, I've finally decided to make my own structs based on data base discussions here earlier. In particular, for this case,
where you want a temp with no random access, a linked list may be just fine. Consider list elements that have int
arrays of fixed size. If the intvector implementation isn't all that efficient, and you don't need random access, you
can just link a bunch of these together and do system.arraycopy() to move the pieces into a final location etc.
04-24-2009 05:47 AM
04-24-2009 06:31 AM
What's your memory constraint? If it is large then yeah having to have two complete copies for a brief moment cuts
your maximum size. The blocking approach would address that problem, depending on your access patterns. Where
do you get a large amount of data with unknown size? Server would know file size usually. However, if that is the case, even
if data is static thereafter, a linked list of arrays may be a good way to go but it really depends on how you
will access the data and to some extent on underlying architecture ( flat memory or disk etc).
Its hard to beat native implementations of anything but sometimes a few pointers or indicies etc can bea big plus when combined with things like system.arraycopy and the RIM array support.
I just got a first implementation of a B-tree going but look at things like the B+ trees etc.