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
mem
size
ctx
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_ctx()must be called with aREAD_WRITEtransaction. Typically it is used when a database write operation fails due to low memory.
MCO_S_OK
MCO_E_NOINSTANCE
MCO_ERR_TRN
MCO_E_ILLEGAL_PARAM
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();
...
}
}
}