I have a couple of binary files that are used in image processing where the data is in float form and is used frequently. The calculations include multiplication and addition of pixels from images taken by the camera.
At present the files are stored as Resources in the /res folder and I am using a DataInputStream each time the file is used, where the data is read and calculated in a single function.
I am relatively new to using files in applications, especially on Android, and so I wanted to find out if there is a better practice to getting data from a file, for instance as I am using the same data over and over again is it better to read the data and store it in an array or even in the SQLite database. This is a augmented reality application so the processed images need to be displayed in near real time.
Many thanks in advance.
EDIT: Thank you Patthoyts for your answer, on a different question however, Why people say mmap by MappedByteBuffer is faster?, I’ve read that using a MappedByteBuffer is not needed as I am reading my data sequentially each time. Could someone with experience on Android tell me whenever it is better to read the data in at the start and store it in a large array or buffer, or to keep reading it from a stream each time I need it. Overall I have around 50,000 floating point values.
You can use memory-mapped files on Android which means the data can be paged into memory by the OS for rapid access until something else needs memory. You need to copy your data file out of your res/raw or assets section to the data filesystem though but after that you can use a MappedByteBuffer to provide access. eg:
now access as sequence of integers using
intbuffer.get(index)and so on.