Search code examples
vectorjava-merms

J2ME - Read directly from RecordStores or store records in a Vector as they're added and retrieve them from that vector later


How do you usually work with the data contained in a RecordStore:

  1. Do you always "query" directly the RecordStore when you have to perform some operations over its records (searching, sorting,etc) or
  2. Do you "cache" those records in a vector or array so that you query that vector or array later, instead of the RecordStore?

Personally, I was following the second approach until yesterday when I got a nasty exception, reminding me that memory is a luxury we should be really careful about when developing j2me apps :S Taking memory in consideration, now I'm not really sure that keeping arrays would be such a good idea. In any case, I would like to hear your opinions guys.After all, you've got more experience.

Thanks for your time.


Solution

  • That depends on the number of records and the size of each record.

    If you have already had OOME with the Vector approach, then try to work with only a single register at a time.

    If you structure well your record you can do some fast searches on it. String searches will probably be slower.

    Keep in mind that, although RMS has no fixed max size, it is advisable to call RecordStore.getSizeAvailable to give you an idea of how much info you can store in a given device.

    Here you have a good tutorial on RMS:
    http://www.ibm.com/developerworks/library/j-j2me3/