DirInternal vs DirInternalCache

socialnetis

Active Member
Licensed User
Longtime User
Hi, I have an app that in every session downloads a bunch of bitmaps from internet, and in order to not run out of memory by having all of them in memory, I write them to disk, and when I want to display them I just read them.

So, I need this read to be as fast as possible (I use a Custom ListView, so the user may want to scroll very fast)
In every session there are about 16mb in images. I assume that DirInternal IS faster than DirExternal, due to the fact that the internal storage comes with the phone, and the external is an sdCard.

I would like to know if this DirInternalCache is a special Cache memory that is really optimized to fast read/write request, or is just as fast as the DirInternal memory?
 

NFOBoy

Active Member
Licensed User
Longtime User
From B4A:

DirInternalCache As String [read only]
Returns the folder in the device internal storage that is used to save application cache data.
This data will be deleted automatically when the device runs low on storage.

From Android Developer

To read a file from internal storage:

Call openFileInput() and pass it the name of the file to read. This returns a FileInputStream.
Read bytes from the file with read().
Then close the stream with close().

Tip: If you want to save a static file in your application at compile time, save the file in your project res/raw/ directory. You can open it with openRawResource(), passing the R.raw.<filename> resource ID. This method returns an InputStream that you can use to read the file (but you cannot write to the original file).
Saving cache files

If you'd like to cache some data, rather than store it persistently, you should use getCacheDir() to open a File that represents the internal directory where your application should save temporary cache files.

When the device is low on internal storage space, Android may delete these cache files to recover space. However, you should not rely on the system to clean up these files for you. You should always maintain the cache files yourself and stay within a reasonable limit of space consumed, such as 1MB. When the user uninstalls your application, these files are removed.


It appears that it is not optimized in the way that you are hoping, but I would think that normal File.DirInternal would be fast enough for your needs.
 
Upvote 0

socialnetis

Active Member
Licensed User
Longtime User
Thanks for replaying, I have made some optimizations, and right now the DirDefaultExternal is doing good, I can scroll really fast and the images are read very fast, the scroll is really smoth. Just from time to time, have some "jumps" but its really acceptable (tested in a Motorola Defy, which is really old by now, and also tested in a samgung galaxy tab 2, in which there are not "jumps" at all, the scroll is really smooth)

The only problem that I found with DirInternal, is that low-end devices like Samsung Galaxy Y and Y Pro (which are really popular in south-America), runs out of internal memory really fast, they have to be very carefully with the installed apps, and from time to time, need to uninstall some because there are no more storage.

So by now, I'm going for the External Storage, and see what happens
 
Upvote 0

NFOBoy

Active Member
Licensed User
Longtime User
That is seeming to pop up for one of my apps quite a bit. (At least something memory/storage related) And I haven't been able to squish that bug yet.
 
Upvote 0
Top