Corporate Logo
Skip Navigation Links
Home
ProductsExpand Products
DownloadsExpand Downloads
AboutExpand About
News
Contact
Account
Purchase
Metrics
Support
 

Check back regularly as we announce further information about this important release.

Beta 2 now includes full support for Vista and Windows Server 2008.
Code Examples
This page contains rudimentary code snippets that serve to show how Persistore is actually used in application code.

This snippet shows how straightfoward it is to create and load a new repository. Once loaded it becomes possible to create directories, shared variables etc as well as persist objects. Simply by terminating the application, all data will be safely retained and visible when next loaded.


/*---------------------------------------*/
/* Create a new, empty 16 Meg repository */
/*---------------------------------------*/

Repository db;

db = new Repository();

db.Load(AllocationMode.Standard,
        AccessMode.Unprotected, 
        BackingMode.Persistent, 
        "test_file",
        4096,
        true); // true forces a create 

if (db.Loaded == false)
   // Error, unable to create new repository



This snippet explains how directories are created both in the repository root and within any other directory. The second string argument in the first two CreateDir methods is the info string that is visible in the repository analyzer when one hovers the mouse pointer over the directory.


/*------------------------------------------*/
/* Create two directories at the root level */
/*------------------------------------------*/

Dir newdir1;
Dir newdir2;

newdir1 = db.CreateDir("new_dir_1","A test dir");
newdir2 = db.CreateDir("new_dir_2","A test dir");

/*--------------------------------------*/
/* Create two sub-dirs beneath each dir */
/*--------------------------------------*/

Dir subdir1_1;
Dir subdir1_2;
Dir subdir2_1;
Dir subdir2_2;

subdir1_1 = newdir1.CreateDir("new_sub_1_1");
subdir1_2 = newdir1.CreateDir("new_sub_1_2");
subdir2_1 = newdir1.CreateDir("new_sub_2_1");
subdir2_2 = newdir1.CreateDir("new_sub_2_1");


This next example shows how create a shared array of 'double' values. Once created the data in each element is truly shared. Any other process on the same machine that makes any modification to any element, will be modifying the single shared copy. Under a debugger, these assignments can actually be observed in real-time by using the repsoitory analyzer in animate mode to view the shared memory.


/*--------------------------------------------------------*/
/* Create a 2D arrays of 'doubles' in one of the sub dirs */
/* and initialize each element to 100.0                   */
/*--------------------------------------------------------*/

Shared<double> stats = new Shared<double>(subdir1_1,
                                          100.0,
                                          "stats_data",
                                          256,
                                          256);

/*----------------------------------------------------*/
/* Set the first 5 elements in row 0, to 500.0. Lock  */
/* the array while we do this.                        */
/*----------------------------------------------------*/

stats.Lock();

stats[0,0] = 500.0;
stats[0,1] = 500.0;
stats[0,2] = 500.0;
stats[0,3] = 500.0;
stats[0,4] = 500.0;

stats.Unlock();
                     

The next snippet show how one can enumerate elements of a shared array. Enumeration will retrieve an instance of each value type in the array, much as if it were a conventional array and in the same element order as a conventional array.


/*--------------------------------------------------------*/
/* Create a 1D arrays of 'int' in one of the sub dirs     */
/* and initialize each element 0.                         */
/*--------------------------------------------------------*/

Shared<int> ints = new Shared<int>(subdir1_1,
                                   0,
                                   "ints_table",
                                   64);

/*------------------------------------------------------*/
/* Search the array for a negative value. Lock the      */
/* array while we do this.                              */
/*------------------------------------------------------*/

ints.Lock();

foreach (int X in ints)
        {
        if (x < 0)
           break; // do something, negative value found
        }

ints.Unlock();
                     

This snippet shows how one might enumerate every instance of a serialized object of a given class (TestClass). By using the type-parameterized method Persistore is able to efficiently return only the objects of the desired type. Every object returned by this method will have been originally inserted by the 'WriteObject' method.


/*--------------------------------------------------------*/
/* Enumerate all objects of type "TestClass" and add them */
/* to a local collection. Objects are deserialized and    */
/* returned automatically by this method.                 */
/*--------------------------------------------------------*/

Dir subdir = my_repository.GetDir("SavedTestData");

foreach (TestClass temp in subdir.Objects<TestClass>())
        {
        localtable.Add(temp);
        }
                     
Persistore
All content copyright © 2004 - 2008 Morantex Information Systems, Inc.
Morantex™, Persistore™ and NoIO™ are trademarks of
Morantex Information Systems, Inc.
 
AMD Opteron
Number of site visits:  5267