ef2f565971e0996ceb6e1dabdf0a456be8610a61
[oweals/cde.git] / cde / programs / dtinfo / DtMmdb / dstr / memory_pool.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 libraries 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 /*
24  * $XConsortium: memory_pool.h /main/3 1996/06/11 17:17:31 cde-hal $
25  *
26  * Copyright (c) 1993 HAL Computer Systems International, Ltd.
27  * All rights reserved.  Unpublished -- rights reserved under
28  * the Copyright Laws of the United States.  USE OF A COPYRIGHT
29  * NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
30  * OR DISCLOSURE.
31  * 
32  * THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
33  * SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.  USE,
34  * DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
35  * PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
36  * INTERNATIONAL, LTD.
37  * 
38  *                         RESTRICTED RIGHTS LEGEND
39  * Use, duplication, or disclosure by the Government is subject
40  * to the restrictions as set forth in subparagraph (c)(l)(ii)
41  * of the Rights in Technical Data and Computer Software clause
42  * at DFARS 252.227-7013.
43  *
44  *          HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
45  *                  1315 Dell Avenue
46  *                  Campbell, CA  95008
47  * 
48  */
49
50
51
52 #ifndef _memory_pool
53 #define _memory_pool 1
54
55 #include "utility/funcs.h"
56 #include "dstr/dlist_void_ptr_cell.h"
57 #include "dstr/dlist.h"
58 #include "dstr/void_ptr_array.h"
59
60 #define MAX_CHUNK_SZ 128
61
62 class chunk_carrier;
63
64 class chunk_manage_record_t : public dlist_cell
65 {
66
67 public:
68    chunk_carrier* chunk_carrier_ptr;
69
70    chunk_manage_record_t( chunk_carrier* chk_carr) :
71       chunk_carrier_ptr(chk_carr) {};
72    virtual ~chunk_manage_record_t() {};
73 };
74
75 typedef chunk_manage_record_t* chunk_manage_recordPtr;
76
77
78 class chunk_carrier
79 {
80
81 public:
82    chunk_carrier(int chunk_sz, int chunks);
83    virtual ~chunk_carrier();
84
85    dlist* init_ptrs();
86
87 protected:
88    int alloc_sz;
89    int chunk_sz;
90    int max_chunks;
91    char* carrier_ptr;
92
93    friend class fix_chunk_pool;
94    friend class memory_pool;
95 };
96
97
98 class fix_chunk_pool 
99 {
100
101 public:
102    fix_chunk_pool(int chunk_sz);
103    virtual ~fix_chunk_pool();
104
105 // return char*
106    virtual char* alloc();
107
108 // free a char*
109    virtual void free(char*); 
110
111 protected:
112    int chunk_sz;
113    int chunks;
114    dlist chunk_carrier_list;
115    dlist free_chunk_list;
116
117    void init_one_chunk_carrier();
118 };
119
120
121 typedef void_ptr_array vm_pool_array_t;
122
123 class memory_pool
124 {
125
126 public:
127    memory_pool(int max_alloc_size = MAX_CHUNK_SZ);
128    virtual ~memory_pool();
129
130 // return char*
131    virtual char* alloc(size_t sz); 
132
133 // free a char*
134    virtual void free(char*); 
135
136 protected:
137    int max_alloc_size_from_pool;
138    vm_pool_array_t vm_pool_vector; 
139 };
140
141 #ifdef C_API
142 #define g_memory_pool (*g_memory_pool_ptr)
143 extern memory_pool* g_memory_pool_ptr;
144 #endif
145
146 #endif