Store to Ram

btechnet

New Member
Licensed User
Longtime User
Been working with B4A for a little while. Currently im working on an app that uses sqlite.

A brief overview:

The app opens and immediately downloads a sqlite.db from a smb server. B4A opens the db and gets the row count. Then the code is written to iterate through the rows one by one until it reaches the last, which then the sqlite.db is downloaded again.

The problem I foresee, if I continually download the file, at some point the internal memory (or external memory) will be basically destroyed from all the continual writes to that flash memory.

Is there anyway to map a chunk of Ram memory to say a "virtual ram drive" using B4A? And how do i download that to Ram memory using smb?

Thanks for the help

Btech
 

Informatix

Expert
Licensed User
Longtime User
The problem I foresee, if I continually download the file, at some point the internal memory (or external memory) will be basically destroyed from all the continual writes to that flash memory.

You'll have probably replaced your phone before reaching the writing limit of modern storage cards. Or you have a very cheap and very old phone.

You can store the database in memory if you use the special location ":memory:" (instead of a filename).
 
Upvote 0

btechnet

New Member
Licensed User
Longtime User
You can store the database in memory if you use the special location ":memory:" (instead of a filename).

I have no problem storing the database in memory, but as I said, I want to download through SMB to memory with no flash memory in between.

I realize that it will take a long time to corrupt any memory, but this program is designed to run a really long time too. (since the database is updated every second i can see it taking a toll real fast)

Im just looking for a way to take a network file "smb://myipaddress/database.db" and instead of using File.DirRootExternal, use File.RamDrive (or something to that effect)
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
I have no problem storing the database in memory, but as I said, I want to download through SMB to memory with no flash memory in between.

Memory is scarce on our devices. You should spare it as much as possible.

Since last year, I probably wrote a few thousands times (at least) in various databases or cache folders on my device and I didn't lose one byte of storage space.
 
Upvote 0

btechnet

New Member
Licensed User
Longtime User
I realize that ram is scarce but I only need 16k - 20k of space.


I have found a way to make a ram drive using this information:

Use a terminal emulator, or adb



create a dir somewhere, mkdir /sdcard/ram

and then

mount -t tmpfs -o size=1M,mode=0744 tmpfs /sdcard/ram


Now this is mounted to location SDCARD, but it is basically a symlink to ram. It doesn't actually use sd memory.

This will be erased from memory after a reboot. But if the program is designed correctly then you should be able to reload the ram drive once the program loads.

tmpfs is obvious (temporary file system)
size=(actual size you need followed by a capitalized letter size (K for Kilobytes, M for Megabytes))
 
Upvote 0

btechnet

New Member
Licensed User
Longtime User
Just updating my previous post.

Mounting a ramdrive only works on adb. There is not way to do it progmatically since the phone would have to be rooted. I did root one and found out that there is no reliable way to call "su" in B4A. I used the phone library which has the shell command built in.

Everytime i called su, the program locked up.

I also tried su - c 'mount -t tmpfs -o size=1M,mode=0744 tmpfs /sdcard/ram'

That errors out saying that the usage of su -c is wrong

Still trying other methods
 
Upvote 0
Top