]>
git.saurik.com Git - apt.git/blob - apt-pkg/contrib/mmap.h
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: mmap.h,v 1.7 1998/11/12 03:14:40 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 ##################################################################### */
25 // Header section: pkglib
30 #pragma interface "apt-pkg/mmap.h"
34 #include <apt-pkg/fileutl.h>
46 bool Close(bool DoClose
= true,bool DoSync
= true);
50 enum OpenFlags
{NoImmMap
= (1<<0),Public
= (1<<1),ReadOnly
= (1<<2)};
53 inline operator void *() {return Base
;};
54 inline void *Data() {return Base
;};
55 inline unsigned long Size() {return iSize
;};
59 bool Sync(unsigned long Start
,unsigned long Stop
);
61 MMap(FileFd
&F
,unsigned long Flags
);
65 class DynamicMMap
: public MMap
69 // This is the allocation pool structure
72 unsigned long ItemSize
;
79 unsigned long WorkSpace
;
81 unsigned int PoolCount
;
86 unsigned long RawAllocate(unsigned long Size
,unsigned long Aln
= 0);
87 unsigned long Allocate(unsigned long ItemSize
);
88 unsigned long WriteString(const char *String
,unsigned long Len
= 0);
89 inline unsigned long WriteString(string S
) {return WriteString(S
.begin(),S
.size());};
90 void UsePools(Pool
&P
,unsigned int Count
) {Pools
= &P
; PoolCount
= Count
;};
92 DynamicMMap(FileFd
&F
,unsigned long Flags
,unsigned long WorkSpace
= 2*1024*1024);
93 virtual ~DynamicMMap();