Link with C++ linker
[oweals/cde.git] / cde / programs / nsgmls / Allocator.h
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: Allocator.h /main/1 1996/07/29 16:46:04 cde-hp $ */
24 // Copyright (c) 1994 James Clark
25 // See the file COPYING for copying permission.
26
27 #ifndef Allocator_INCLUDED
28 #define Allocator_INCLUDED 1
29
30 #include <stddef.h>
31
32 #ifdef SP_NAMESPACE
33 namespace SP_NAMESPACE {
34 #endif
35
36 class SP_API Allocator {
37 public:
38   Allocator(size_t maxSize, unsigned blocksPerSegment);
39   ~Allocator();
40   void *alloc(size_t);
41   static void *allocSimple(size_t);
42   static void free(void *);
43
44   // It would be nice to make these private, but some compilers have problems.
45   union ForceAlign {
46     unsigned long n;
47     struct SP_API {
48       char c;
49     } s;
50     char *cp;
51     long *lp;
52   };
53   struct SegmentHeader;
54   union BlockHeader;
55   friend union BlockHeader;
56   union BlockHeader {
57     SegmentHeader *seg;
58     ForceAlign align;
59   };
60   struct Block;
61   friend struct Block;
62   struct SP_API Block {
63     BlockHeader header;
64     Block *next;
65   };
66   friend struct SegmentHeader;
67   struct SP_API SegmentHeader {
68     union {
69       Block **freeList;
70       ForceAlign align;
71     };
72     unsigned liveCount;
73     SegmentHeader *next;
74   };
75 private:
76   Allocator(const Allocator &); // undefined
77   Allocator &operator=(const Allocator &); // undefined
78   Block *freeList_;
79   size_t objectSize_;
80   unsigned blocksPerSegment_;
81   SegmentHeader *segments_;
82   void *alloc1();
83   void tooBig(size_t);
84 };
85
86 #ifdef SP_NAMESPACE
87 }
88 #endif
89
90 #endif /* not Allocator_INCLUDED */