Symisc UnQLite

An Embeddable NoSQL Database Engine



UnQLite C/C++ API Reference - Read-only memory view.

Syntax

int unqlite_util_load_mmaped_file(const char *zFile,void **ppMap,unqlite_int64 *pFileSize);
int unqlite_util_release_mmaped_file(void *pMap,unqlite_int64 iFileSize);


Obtain a read-only memory view of the target file.


Description


The unqlite_util_load_mmaped_file() interface is used to obtain a read-only memory view of the whole target file. This is very useful especially if you want to store files perhaps some configurations inside your UnQLite database (See example below). On success, the memory view is stored in ppAddr and the file size in bytes is stored in pFileSize.


unqlite_util_release_mmaped_file() release the memory view of the target file after successful return from unqlite_util_load_mmaped_file().


Parameters


zFile

Relative or real path to the target file.

ppMap

OUT: Read-only memory view of the whole file.

pFileSize

OUT: Size in bytes of the target file.


Return value


UNQLITE_OK is returned on success with a read-only memory view of the whole file stored in ppAddr (Second argument) and the size of the target file in bytes stored in pFileSize (Third argument). Any other return value indicates failure.


Example


Compile this C file for a smart introduction to these interfaces.


#include <unqlite.h>

void
*pMap;
unqlite_int64 iSize;
int rc;
unqlite *pDb;

// Open our database;
rc = unqlite_open(&pDb,"test.db",UNQLITE_OPEN_CREATE);
if( rc != UNQLITE_OK ){ return; }

// Obtain a read-only memory view of the target file;
rc = unqlite_util_load_mmaped_file("target.xml",&pMap,&iSize);
if( rc != UNQLITE_OK ){ return; }

// Store the whole file in our database;
rc = unqlite_kv_store(pDb,"target.xml",-1,pMap,iSize);
if( rc != UNQLITE_OK ){ return; }

// Discard the memory view;
unqlite_util_release_mmaped_file(pMap,iSize);

//Auto-commit the transaction and close our handle
unqlite_close(pDb);


See also


unqlite_util_random_string.



Symisc Systems
Copyright © Symisc Systems