Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 17 » UltraLite - Database Management and Developer Guide » UltraLite performance tips

Cache size adjustment for an UltraLite database

Although adjusting the cache size is not required, you should adjust the cache size when your UltraLite database application is requested to reduce its memory usage by the operating system on mobile devices.

UltraLite database cache sizes increase dynamically in response to data operations and as available device memory allows within the parameters you specify. Normally you do not need to specify any parameters. If your database is large (400 MB for instance), you may want to specify the CACHE_MAX_SIZE parameter to raise the maximum limit beyond the default. UltraLite allocates some data structures based on the maximum cache size, so the default is not extremely large: you must explicitly request a large maximum to incur this extra memory overhead. There is no benefit to specifying a maximum cache size that is much larger than your maximum actual database file size.

UltraLite does not shrink the cache automatically. The database cache size can only be controlled explicitly in your application with the cache_allocation database option. In response to a low memory event raised by the operating system, adjust the cache_allocation database option after connecting to the database.

Example

The following UltraLite C++ code sample illustrates how to set the maximum cache size to 100 MB by updating the connection string:

static ul_char const * ConnectionParms =
    "UID=DBA;PWD=sql;DBF=sample.udb;CACHE_MAX_SIZE=100m";

The following UltraLite C++ code sample illustrates how to reduce the cache allocation in half to resize the cache:

ULConnection * conn = ULDatabaseManager::OpenConnection(ConnectionParms);
ul_u_long percent;
percent = conn->GetDatabasePropertyInt( "cache_allocation" );
conn->SetDatabaseOptionInt( "cache_allocation", percent / 2 );