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.
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 :)
Asked in February 2016Viewed 3,732 timesVoted 7Answered 2 times