Click here to Skip to main content
13,352,157 members (76,987 online)
Click here to Skip to main content
Add your own
alternative version


26 bookmarked
Posted 6 Apr 2003

Memory mapped files and flat table primitives.

, 6 Apr 2003
Rate this:
Please Sign up or sign in to vote.
Source C++ classes for persisting flat table data.


Let's say you need to store and read an array of some structures to or from the hard drive in your application.

For instance: you may have a structure like this:

struct record {
  char first_name[32];
  char last_name[64];
  record() { first_name[0] = 0; last_name[0] = 0; }
  void set(const char* first, const char *last)
    strncpy(first_name, first, sizeof(first_name)-1);
    strncpy(last_name, last, sizeof(last_name)-1);

And you would like to persist an array of them.

Instead of using expensive (in many senses) classical database solution, you may write the following:

#include "tl_mm_file.h"

int main(int argc, char* argv[])
  tool::table<record> tbl;

/* writing/creating table of "record"s */"c:/test.tbl",true);



/* reading it */"c:/test.tbl");
  for(unsigned int i = 0; i <; i++)
    printf("%s %s\n",
      tbl(i).last_name );

 return 0;

You just need to include mm_file.h and mm_file.cpp in your project and you are done.


  1. Easy and fast. This method of accessing persistent data has nearly zero time overload for opening/closing datasets and eliminates need of intermediate buffers a.k.a. "current record".
  2. It provides direct access to the records in the table in a random manner.
  3. Compact and self-sufficient implementation.


  1. Only fixed size structures are supported.
  2. Access by key (hash-table, b-tree, etc.) should be implemented separately (if needed).


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Founder Terra Informatica Software
Canada Canada
Andrew Fedoniouk.

MS in Physics and Applied Mathematics.
Designing software applications and systems since 1991.

W3C HTML5 Working Group, Invited Expert.

Terra Informatica Software, Inc.

You may also be interested in...


Comments and Discussions

GeneralVery Good Stuff Pin
AbhishekBK28-Apr-06 1:08
memberAbhishekBK28-Apr-06 1:08 
QuestionCan you add multi-table support? Pin
任远科9-Jan-04 21:13
member任远科9-Jan-04 21:13 
AnswerRe: Can you add multi-table support? Pin
c-smile9-Jan-04 22:22
memberc-smile9-Jan-04 22:22 
GeneralRe: Can you add multi-table support? Pin
任远科10-Jan-04 7:10
member任远科10-Jan-04 7:10 
GeneralGood approach but... Pin
Dimitris Vassiliades9-Apr-03 12:51
memberDimitris Vassiliades9-Apr-03 12:51 
The title is a little bit confusing and the short article helps on this too.
I was wondering why do something like this, since you can have CMemFile for memory mapped files. Are you trying to provide temporary memory tables?
GeneralRe: Good approach but... Pin
c-smile9-Apr-03 13:34
memberc-smile9-Apr-03 13:34 
GeneralRe: Good approach but... Pin
raminx14-Apr-03 22:54
memberraminx14-Apr-03 22:54 
GeneralRe: Good approach but... Pin
c-smile15-Apr-03 9:12
memberc-smile15-Apr-03 9:12 
GeneralRecommendations Pin
peterchen7-Apr-03 2:21
memberpeterchen7-Apr-03 2:21 
GeneralThanks Pin
jhaga7-Apr-03 1:30
memberjhaga7-Apr-03 1:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.180111.1 | Last Updated 7 Apr 2003
Article Copyright 2003 by c-smile
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid