Symisc UnQLite

An Embeddable NoSQL Database Engine

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


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.


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().



Relative or real path to the target file.


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


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.


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

#include <unqlite.h>

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;

//Auto-commit the transaction and close our handle

See also


Symisc Systems
Copyright © Symisc Systems