For C# applications using in-memory databases, a single conventional memory device required for all database data, indexes and metadata is automatically defined and initialized in the Database.Open() method when no device array is specified. For example, the typical sequence of API calls that uses the default device initialization could look like the following:
class Obj { [Indexable(Type=Database.IndexType.BTree, Unique=false)] // Declare non-unique tree index by "value" field public int value; } public static void Main(String[] args) { const int PAGE_SIZE = 128; const int DATABASE_SIZE = 16*1024*1024; ... Database db = new Database(new ExtremedbWrapper()); Database.Parameters parameters = new Database.Parameters(); ... parameters.MemPageSize = PAGE_SIZE; parameters.Classes = new Type[]{typeof(Obj)}; ... db.Open("tree-db", parameters, DATABASE_SIZE); ... }
However, C# applications can override the default device initialization by specifying an array of memory devices to pass to the Database.Open() method. For example, to define a shared memory device, the application code could look like the following:
class Obj { [Indexable(Type=Database.IndexType.BTree, Unique=false)] public int value; } public static void Main(String[] args) { const int PAGE_SIZE = 128; const int DATABASE_SIZE = 16*1024*1024; ... Database db = new Database(new ExtremedbWrapper()); Database.Device[] devs; char * dbName = "openDb"; char * shareName = "openDb-db"; int hint = 0; Database.Parameters parameters = new Database.Parameters(); ... parameters.MemPageSize = PAGE_SIZE; parameters.Classes = new Type[]{typeof(Obj)}; ... devs = new Database.Device[1]; devs[0] = new Database.SharedMemoryDevice(Database.Device.Kind.Data, shareName, new IntPtr(hint), DATABASE_SIZE); ... db.Open(dbName, parameters, devs); ... }Note that a shared memory device must specify the shared memory name, a "hint" address for the shared memory segment and the total database size.
Persistent Databases
Applications using persistent databases must define an array of at least four memory devices to manage the following distinct memory regions:
For a typical persistent database application the memory devices could be defined as follows:
const int N_DEVICES 4; const int PAGE_SIZE = 128; const int DISK_PAGE_SIZE = 4096; const int DISK_CACHE_SIZE = 8*1024*1024; const int DATABASE_SIZE = 16*1024*1024; Database.Device[] devs = new Database.Device[N_DEVICES]; devs[0] = new Database.PrivateMemoryDevice(Database.Device.Kind.Data, DATABASE_SIZE); devs[1] = new Database.PrivateMemoryDevice(Database.Device.Kind.DiskCache, DISK_CACHE_SIZE); devs[2] = new Database.FileDevice(Database.Device.Kind.Data, "opendb.dbs"); devs[3] = new Database.FileDevice(Database.Device.Kind.TransactionLog, "opendb.log");