1 // -*- mode: cpp; mode: fold -*-
3 // $Id: mmap.h,v 1.2 1999/10/24 06:53:12 jgg Exp $
4 /* ######################################################################
6 MMap Class - Provides 'real' mmap or a faked mmap using read().
8 The purpose of this code is to provide a generic way for clients to
9 access the mmap function. In enviroments that do not support mmap
10 from file fd's this function will use read and normal allocated
13 Writing to a public mmap will always fully comit all changes when the
14 class is deleted. Ie it will rewrite the file, unless it is readonly
16 The DynamicMMap class is used to help the on-disk data structure
17 generators. It provides a large allocated workspace and members
18 to allocate space from the workspace in an effecient fashion.
20 This source is placed in the Public Domain, do with it what you will
21 It was originally written by Jason Gunthorpe.
23 ##################################################################### */
29 #pragma interface "dsync/mmap.h"
33 #include <dsync/fileutl.h>
35 /* This should be a 32 bit type, larger tyes use too much ram and smaller
36 types are too small. Where ever possible 'unsigned long' should be used
37 instead of this internal type */
38 typedef unsigned int map_ptrloc;
49 bool Close(bool DoSync = true);
53 enum OpenFlags {NoImmMap = (1<<0),Public = (1<<1),ReadOnly = (1<<2),
57 inline operator void *() {return Base;};
58 inline void *Data() {return Base;};
59 inline unsigned long Size() {return iSize;};
63 bool Sync(unsigned long Start,unsigned long Stop);
65 MMap(FileFd &F,unsigned long Flags);
66 MMap(unsigned long Flags);
70 class DynamicMMap : public MMap
74 // This is the allocation pool structure
77 unsigned long ItemSize;
85 unsigned long WorkSpace;
87 unsigned int PoolCount;
92 unsigned long RawAllocate(unsigned long Size,unsigned long Aln = 0);
93 unsigned long Allocate(unsigned long ItemSize);
94 unsigned long WriteString(const char *String,unsigned long Len = (unsigned long)-1);
95 inline unsigned long WriteString(string S) {return WriteString(S.c_str());};
96 void UsePools(Pool &P,unsigned int Count) {Pools = &P; PoolCount = Count;};
98 DynamicMMap(FileFd &F,unsigned long Flags,unsigned long WorkSpace = 2*1024*1024);
99 DynamicMMap(unsigned long Flags,unsigned long WorkSpace = 2*1024*1024);
100 virtual ~DynamicMMap();