Create/Open Databases in C#

As demonstrated in the C# Quick Start, databases are created by the Database method Open(). There are three versions of the Open() method:

 
    Open( String dbName, Parameters params, long size)
 
    Open( String dbName, Parameters params, Devices[] devices)
     
    Open( String dbName, Parameters params)
 

The first version is appropriate for In-Memory databases as it allows simply specifying the database size as the third argument. The second version is necessary if a shared memory device or additional memory devices are required, which is typically necessary only for persistent databases. However for an In-Memory database an additional one or more memory devices could be necessary if database memory might need to be extended. The third version actually calls the second version with devices = null which is used when opening an existing shared memory database.

For an in-memory database the relevant parameters are described below. For persistent databases there are additional considerations. Please use the following link to view detailed instructions for creating or opening persistent databases.

Database Parameters

The Database.Parameters class is used to specify the classes that will be stored in the eXtremeDB database and other properties that determine runtime behavior. The Database.Parameters constructor initializes the database parameters with default values. For In-Memory databases, apart from the default values, typically the only parameters to specify are MemPageSize, Classes and MaxConnections. For example:

     
    public static void main(String[] args)
    {
        ...
        Database.Parameters params = new Database.Parameters();
        ...
        params.MemPageSize = 128; // Memory page size
        params.Classes = new Class[] { OpenObj.class }; // List of classes that will be stored in eXremeDB database.
        params.MaxConnections = 10;
         

The key properties of the Database.Parameters class for in-memory databases are:

MemPageSize The size in bytes of the database object and index pages
DiskPageSize Set to zero to indicate an in-memory database (and disable disk operations)
Classes The list of Java classes that will be stored in eXtremeDB database (The classes must use @Persistent annotation)
MaxConnections The total number of connections allowed to the database

Memory page size

The MemPageSize property defines the size of memory pages for conventional memory. The MemPageSize can be calculated to optimize performance and will vary depending on the application dynamics, but as a rule of thumb, page size should be between 80 and 512 bytes; a 128 byte page size is good in most situations.

(Note that for all-in-memory databases DiskPageSize will be set to zero by the Database.Parameters constructor.)

(Also note that rtree indexes require larger page sizes. If error codes MCO_ERR_RTREE or MCO_E_DISK_PAGE_POOL_EXHAUSTED are encountered during database transactions, increase the page size in increments until these error codes are remedied.)

Max database connections

The MaxConnections property specifies the maximum number of connections that will be managed for this database.

Example

Typical application code to create an in-memory database could look like the following:

     
    const int DATABASE_SIZE = 16*1024*1024;
     
    public static void main(String[] args)
    {
        Database db = new Database();
        Database.Parameters params = new Database.Parameters();
        ...
        params.MemPageSize = 128; // Memory page size
        params.Classes = new Type[] { typeof(Record) }; // List of classes that will be stored in eXremeDB database.
         
        db.Open("operations-db", params, DATABASE_SIZE);