extend.c

来自「extremeDB s sample code,useful for you」· C语言 代码 · 共 124 行

C
124
字号
/*************************************************************** *                                                             * * Copyright (c) 2001-2006 McObject LLC. All Right Reserved.   * *                                                             * ***************************************************************//* * This sample demonstarates database extention API - * mco_db_extend() */#include "platform.h"#include <stdio.h>#include <stdlib.h>#include "samples.h"static const char   *   dbname       = "SimpleDb";static const int        FIRST_SEGSZ  = 1024 * 2000UL;static const int        SECOND_SEGSZ = 1024 * 6000UL;#ifndef MCO_PLATFORM_X64static const int        PAGESIZE = 96;#elsestatic const int        PAGESIZE = 192;#endifvoid _SH_(void) {	char text[] = {		"\nThis example demonstrates eXtremeDB memory extension API\n"		"\nCopyright (c) 2001-2006 McObject LLC. All Right Reserved.\n\n"	};	printf("%s\nPress Enter to start", text);}/* Produces database memory report */void showMem( mco_db_h db ) {	mco_puint freepg, totalpg;	mco_db_free_pages( db, & freepg );	mco_db_total_pages( db, & totalpg );	printf(	"\n\tMemory Report:\n\ttotal pages=%d (%dK)\n\tfree pages=%d (%dK)\n\tused %dK\n",		totalpg,		totalpg * PAGESIZE / 1024,		freepg,		freepg * PAGESIZE / 1024,		(totalpg - freepg) * PAGESIZE / 1024		);}/* fatal error handler */static void errhandler( int n ) {	printf( "\neXtremeDB fatal error: %d", n );	getchar();	exit( -1 );}int main( void ) {	MCO_RET     rc;	mco_db_h    db = 0;	char      	*start_mem1 = 0;	char      	*start_mem2 = 0;	mco_runtime_info_t info;	_SH_();	mco_get_runtime_info( &info);	if ( info.mco_shm_supported ) {		printf("\nDatabase extention API is not available for the shared memory database runtime\n");		exit (1);	};	start_mem1 = malloc( FIRST_SEGSZ );	/* set fatal error handler */	mco_error_set_handler( &errhandler );	mco_runtime_start();	printf("\nAllocating initial memory pool of %dK for the database at the 0x%x\n",		FIRST_SEGSZ/1024, start_mem1);			/* Create a database, using first memory segment */	rc = mco_db_open( dbname, simple_get_dictionary(), start_mem1, FIRST_SEGSZ, (uint2) PAGESIZE );	if ( rc ) {		printf( "\nerror creating database %d", rc );		mco_runtime_stop();		exit( 1 );	}	/* connect to the database, obtain a database handle */	mco_db_connect( dbname, &db );	showMem( db );	/* allocate the second database segment and "extend" the database */	start_mem2 = ( SECOND_SEGSZ > 0 ) ? malloc( SECOND_SEGSZ ) : 0;	printf("\nExtending the database memory pool by %dK at the 0x%x\n",		SECOND_SEGSZ/1024, start_mem2);	if ( start_mem2 ) mco_db_extend( dbname, start_mem2, SECOND_SEGSZ );	showMem( db );	/* disconnect from the database, db is no longer valid */	mco_db_disconnect( db );	/* destroys the memory manager */	mco_db_close( dbname );	mco_runtime_stop();	if( start_mem1 ) free(start_mem1);	if( start_mem2 ) free(start_mem2);	printf( "\nPress Enter to finish\n" );	getchar();  PROG_EXIT(0);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?