Keenan Gebze February 2016

Is there an optimum point between saving data in memory and writing it to drive?

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?

Answers


Makandal February 2016

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.


Ales February 2016

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

Post Status

Asked in February 2016
Viewed 3,732 times
Voted 7
Answered 2 times

Search




Leave an answer