main.c

来自「eXtremeDB数据库在Linux平台下的使用源码。内含多个示例程序」· C语言 代码 · 共 108 行

C
108
字号
/*************************************************************** *                                                             * * Copyright (c) 2001-2007 McObject LLC. All Right Reserved.   * *                                                             * ***************************************************************//* This samples demonstartes eXtremeDB patricia tree *match functions behaviour. */#include <stdio.h>#include <stdlib.h>#include <string.h>#include "simple.h"#include "objfunc.h"static const char   *   dbname = "SimpleDb";static const int        FIRST_SEGSZ = 1024 * 8000UL;#ifndef MCO_PLATFORM_X64static const int        PAGESIZE = 96;#elsestatic const int        PAGESIZE = 192;#endifconst int MAP_ADDRESS =  0x20000000;void _SH_(void) {	char text[] = {		"\nThis samples demonstartes eXtremeDB patricia tree *match functions behaviour.\n"	};	char text1[] = {		"Copyright (c) 2001-2007 McObject LLC. All Right Reserved.\n\n"	};	printf("%s\neXtremeDB runtime version %d.%d, build %d\n%s\n\nPress Enter to start",		text, MCO_COMP_VER_MAJOR, MCO_COMP_VER_MINOR, MCO_COMP_BUILD_NUM,text1);	getchar();}/* fatal error handler */static void errhandler( int n ) {	printf( "\neXtremeDB runtime fatal error: %d", n );	getchar();	exit( -1 );}int main( void ) {	MCO_RET     rc;	mco_db_h    db = 0;	char    *  start_mem;	mco_runtime_info_t info;	_SH_();	mco_get_runtime_info( &info);	if ( info.mco_shm_supported ) {		start_mem = (char*)MAP_ADDRESS;	}	else {		start_mem = (char*)malloc(FIRST_SEGSZ);		if (!start_mem) {			printf("Couldn't allocated memory\n");			exit (1);		}	};	/* set fatal error handler */	mco_error_set_handler( &errhandler );	mco_runtime_start();	/* Create a database - allocate 2M starting from mem. */	rc = mco_db_open( dbname, simple_get_dictionary(), start_mem, FIRST_SEGSZ, (uint2) PAGESIZE );	if ( rc ) {		printf( "\nerror creating database" );		if ( !info.mco_shm_supported )			free( start_mem );		exit( 1 );	}	/* connect to the database, obtain a database handle */	mco_db_connect( dbname, &db );	printf( "\ndb handle = %d\n", db );	createDatabase( db );	doListing( db );	doGoogle( db );	/* disconnect from the database, db is no longer valid */	mco_db_disconnect( db );	/* destroy the db */	mco_db_close( dbname );	mco_runtime_stop();	if ( !info.mco_shm_supported )		free( start_mem );	printf( "Press Enter key to exit" );	getchar();  exit(0);}

⌨️ 快捷键说明

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