Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
Posts: 3
Registered: ‎04-21-2009
My Device: Not Specified
Accepted Solution

How is performance of IntVector class

Hello All,

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.

 

Suresh Pal,

 

Developer
Posts: 1,415
Registered: ‎07-30-2008
My Device: Not Specified

Re: How is performance of IntVector class

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. 

New Developer
Posts: 3
Registered: ‎04-21-2009
My Device: Not Specified

Re: How is performance of IntVector class

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) :

http://www.blackberry.com/developers/docs/4.7.0api/net/rim/device/api/util/IntVector.html

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.

 

 

Thanks

 

 

Developer
Posts: 1,415
Registered: ‎07-30-2008
My Device: Not Specified

Re: How is performance of IntVector class

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. 

 

New Developer
Posts: 3
Registered: ‎04-21-2009
My Device: Not Specified

Re: How is performance of IntVector class

marchywka,

I think you may be right for implementing own datastructure for this.
But i think for my case the classes like Vector or IntVector are working fine.

Since I was needing to create an array of ints from a vector at run time. I can't afford a vector in my application
because of memory, so I need a fixed size array, but since at runtime I can not get exact size for the items,
so I am creating a vector and then creating array equal to size of array and copying these elements into array.
Then in whole application same array is used.
Also InVector was helpful in the way that it deals with the primitive ints only.

Thanks again......
Developer
Posts: 1,415
Registered: ‎07-30-2008
My Device: Not Specified

Re: How is performance of IntVector class

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 be

a 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.