Extend database memory.
MCO_RET mco_db_extend_ctx( /*IN*/ mco_trans_h t,
/*IN*/ void * mem,
/*IN*/ uint4 size,
/*IN*/ void const* ctx);
| t | The current transaction handle |
| mem | The starting address of a block of memory |
|
size |
The size, in bytes, of the block of memory |
| ctx | The address of database context data or a call to mco_db_connection_context() which returns the address of the context associated with a connection to an existing database |
This function extends the amount of memory used by the database. Note that whereas
mco_db_extend()must be called outside any transaction,mco_db_extend_tmust be called with aREAD_WRITEtransaction. Typically it is used when a database write operation fails due to low memory.
const char * dbname = "SimpleDb";
int main(int argc, char* argv[])
{
mco_db_h db;
MCO_RET rc;
char *mem = malloc( DBSIZE );
if( (rc = mco_runtime_start()) != MCO_S_OK)
exit(-1);
rc = mco_db_open( dbname, simpledb_get_dictionary(), mem, DBSIZE, (uint2)PAGESIZE );
...
rc = mco_db_connect(dbname, &db);
...
/* If low memory situation detected (see "Auxiliary APIs: Statistics") */
mco_db_free_pages(db, &freepages);
mco_db_total_pages(db, &totalpages );
if(freepages < totalpages / 10)
{
// yes. Extend the database
char * mem2 = malloc(SECOND_SEGSZ);
if( mem2 )
{
rc = mco_trans_start(db, MCO_READ_WRITE, MCO_TRANS_FOREGROUND, &t);
rc = mco_db_extend_ctx(t, mem2, SECOND_SEGSZ, mco_db_connection_context());
if ( MCO_S_OK != rc )
mco_trans_rollback();
else
mco_trans_commit();
...
}
}
}