0

I'm developing J2ME application (with SDK 3.4) for my unused J2ME SE Hazel j20i to record GPS data via Location API.

neither CLDC 1.1, MIDP 2.1, nor JSR-75 provide java.io.BufferedWriter. So I do it manually.

How much do I have to store the GPS readings (GPS logging will run indefinitely until stopped) in memory (variables) until I have to write it on disk?

What is best for performance?

Keenan Gebze
  • 1,366
  • 1
  • 20
  • 26

2 Answers2

2

Knowing that write/read hard drive (SD card, etc.) cost more then write/read Memory (RAM) I would suggest you keep track off the memory available while collecting the GPS data and define a threshold to write the data to hard drive. I cannot tell you what is the optimum threshold. You can keep track of the memory like that:

 long totalMemory = Runtime.getRuntime().totalMemory();
 long freeMemory = Runtime.getRuntime().freeMemory();
 if(threshold > freeMemory)
     //1-write to hard drive
     //2-make sure you use the proper mechanism to help the 
     //garbage collector (GC) do its job. ex: reinitialize your data structures, set them to null ... 

Note that the GC might take time before clearing the memory, you would also need to handle that properly because after you clear your data structures your free memory wont become bigger right away it could get to zero before but hopefully the GC will do the job and you won't go out of memory. Don't need to remind you that you have to handle the out of memory scenario! Have a nice day.

Makandal
  • 151
  • 5
0

I guess for a GPS logger performance is not critical, you get location update every second (at best, with Hazel internal GPS receiver, I assume), so the amount of data is low. But buffered writes may save power and increase battery life...

I would buffer output in multiples of 4k (or allocation unit size of your SD), up to, let's say 64k, and do a block write. With bigger buffer you would loose more data when your midlet crashes :)

Ales
  • 168
  • 9