Jump to content
McObject Forums

How can I get the value of needed space for my db

Recommended Posts


Is there a way to get the the size needed to store my exampleData?

I want to check for different databases how much space they need to store exampleData. Therefore I need to know how much space Perstdb needs to store my exampleData. Is there a easy way to get this value?

For example, SQLite stores all data in one file. So I take the size of this file.



Share this post

Link to post
Share on other sites

For example I want to add 5 Elements of my data and look how much space is needed to store  the db.  Then I want to add 5 more and look again. and so on.

Share this post

Link to post
Share on other sites

I tried this.

File f = new File(this.ApplicationContext.getFilesDir().getAbsolutePath() + "/" + databaseName);
long dbSize = f.length();
return dbSize;


I tried to check if this works.

i clear the database, add some example data. check the value.(10506240 bytes)

clear database, add same data again, check the value. (10551296 bytes)

but every time I got a new value.   Is this normal?
If I add my example data in another Database multiple times I always got the same value. Why Perst gives every try another value?

I will attach a screenshot. There you can see other databases already has the same values in different trys.


Share this post

Link to post
Share on other sites

Perst also stores data in one file. So you can estimate the size of the database just by inspecting the size of this file.
Concerning the second question: Perst never shrinks the database file, but it marks deallocated objects as free (and will reuse the space, eventually). Even if your allocated objects have the same size, Perst has to allocate many other kinds of objects of different size: bitmap
pages, index pages, ... It means that if you allocate N objects, then delete all of them and allocate N objects once again, then the resulting size of the database may be alightly larger because of fragmentation. This process should be stabilized after some iterations. It should not be a problem unless you want to estimate the size of the database with "one byte" precision.


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now