1
by brian
clean slate |
1 |
/* Copyright (C) 2000 MySQL AB
|
2 |
||
3 |
This program is free software; you can redistribute it and/or modify
|
|
4 |
it under the terms of the GNU General Public License as published by
|
|
5 |
the Free Software Foundation; version 2 of the License.
|
|
6 |
||
7 |
This program is distributed in the hope that it will be useful,
|
|
8 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
9 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
10 |
GNU General Public License for more details.
|
|
11 |
||
12 |
You should have received a copy of the GNU General Public License
|
|
13 |
along with this program; if not, write to the Free Software
|
|
1802.10.2
by Monty Taylor
Update all of the copyright headers to include the correct address. |
14 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
|
1
by brian
clean slate |
15 |
|
1441.2.3
by Tim Martin
Updating existing comments to doxygen format |
16 |
/**
|
17 |
* @file
|
|
18 |
* @brief Memory root declarations
|
|
19 |
*/
|
|
1
by brian
clean slate |
20 |
|
2234
by Brian Aker
Mass removal of ifdef/endif in favor of pragma once. |
21 |
#pragma once
|
1
by brian
clean slate |
22 |
|
2252.1.12
by Olaf van der Spek
Common fwd |
23 |
#include <drizzled/common_fwd.h> |
575.1.6
by Monty Taylor
Cleaned up some headers for PCH. |
24 |
#include <drizzled/definitions.h> |
2318.9.10
by Olaf van der Spek
Rename strmake to strdup (standard name) |
25 |
#include <drizzled/util/data_ref.h> |
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
26 |
#include <drizzled/visibility.h> |
2119.4.1
by Monty Taylor
Turns on -fvisibility=hidden by default. Symbols intended to be used by |
27 |
|
2252.1.12
by Olaf van der Spek
Common fwd |
28 |
namespace drizzled { |
1441.2.3
by Tim Martin
Updating existing comments to doxygen format |
29 |
|
30 |
/**
|
|
31 |
* @namespace drizzled::memory
|
|
32 |
* Memory allocation utils
|
|
1441.2.5
by Tim Martin
More doxygen commenting |
33 |
*
|
34 |
* NB: This namespace documentation may not seem very useful, but without a
|
|
35 |
* comment on the namespace Doxygen won't extract any documentation for
|
|
36 |
* namespace members.
|
|
1441.2.3
by Tim Martin
Updating existing comments to doxygen format |
37 |
*/
|
2252.1.12
by Olaf van der Spek
Common fwd |
38 |
namespace memory { |
1253.1.1
by Monty Taylor
First bits of namespacing. Ugh. Why do I do this to myself. |
39 |
|
40 |
static const int KEEP_PREALLOC= 1; |
|
41 |
/* move used to free list and reuse them */
|
|
42 |
static const int MARK_BLOCKS_FREE= 2; |
|
43 |
||
2318.6.54
by Olaf van der Spek
Refactor |
44 |
namespace internal |
45 |
{
|
|
46 |
class UsedMemory |
|
47 |
{ /* struct for once_alloc (block) */ |
|
48 |
public: |
|
49 |
UsedMemory *next; /* Next block in use */ |
|
50 |
size_t left; /* memory left in block */ |
|
51 |
size_t size; /* size of block */ |
|
52 |
};
|
|
1253.1.2
by Monty Taylor
We have init_sql_alloc and init_alloc_root - and I can't tell the difference. |
53 |
}
|
54 |
||
55 |
static const size_t ROOT_MIN_BLOCK_SIZE= (MALLOC_OVERHEAD + sizeof(internal::UsedMemory) + 8); |
|
56 |
||
2119.4.1
by Monty Taylor
Turns on -fvisibility=hidden by default. Symbols intended to be used by |
57 |
class DRIZZLED_API Root |
1
by brian
clean slate |
58 |
{
|
1253.1.3
by Monty Taylor
MEM_ROOT == memory::Root |
59 |
public: |
1711.6.5
by Brian Aker
Updating so that structures have constructor (removed memset calls). |
60 |
Root() : |
61 |
free(0), |
|
62 |
used(0), |
|
63 |
pre_alloc(0), |
|
64 |
min_malloc(0), |
|
65 |
block_size(0), |
|
66 |
block_num(0), |
|
2318.6.22
by Olaf van der Spek
Refactor |
67 |
first_block_usage(0) |
1711.6.5
by Brian Aker
Updating so that structures have constructor (removed memset calls). |
68 |
{ } |
69 |
||
1485
by Brian Aker
Updates to confine memroot |
70 |
Root(size_t block_size_arg) |
71 |
{
|
|
72 |
free= used= pre_alloc= 0; |
|
73 |
min_malloc= 32; |
|
74 |
block_size= block_size_arg - memory::ROOT_MIN_BLOCK_SIZE; |
|
75 |
block_num= 4; /* We shift this with >>2 */ |
|
76 |
first_block_usage= 0; |
|
77 |
}
|
|
78 |
||
1441.2.1
by Tim Martin
Reformatting some memory/root.h comments for doxygen |
79 |
/**
|
80 |
* blocks with free memory in it
|
|
81 |
*/
|
|
1253.1.3
by Monty Taylor
MEM_ROOT == memory::Root |
82 |
internal::UsedMemory *free; |
1253.1.2
by Monty Taylor
We have init_sql_alloc and init_alloc_root - and I can't tell the difference. |
83 |
|
1441.2.1
by Tim Martin
Reformatting some memory/root.h comments for doxygen |
84 |
/**
|
85 |
* blocks almost without free memory
|
|
86 |
*/
|
|
1253.1.3
by Monty Taylor
MEM_ROOT == memory::Root |
87 |
internal::UsedMemory *used; |
1253.1.2
by Monty Taylor
We have init_sql_alloc and init_alloc_root - and I can't tell the difference. |
88 |
|
1441.2.1
by Tim Martin
Reformatting some memory/root.h comments for doxygen |
89 |
/**
|
90 |
* preallocated block
|
|
91 |
*/
|
|
1253.1.3
by Monty Taylor
MEM_ROOT == memory::Root |
92 |
internal::UsedMemory *pre_alloc; |
1253.1.2
by Monty Taylor
We have init_sql_alloc and init_alloc_root - and I can't tell the difference. |
93 |
|
1441.2.1
by Tim Martin
Reformatting some memory/root.h comments for doxygen |
94 |
/**
|
95 |
* if block have less memory it will be put in 'used' list
|
|
96 |
*/
|
|
1
by brian
clean slate |
97 |
size_t min_malloc; |
1441.2.1
by Tim Martin
Reformatting some memory/root.h comments for doxygen |
98 |
|
99 |
size_t block_size; ///< initial block size |
|
100 |
unsigned int block_num; ///< allocated blocks counter |
|
101 |
||
102 |
/**
|
|
103 |
* first free block in queue test counter (if it exceed
|
|
104 |
* MAX_BLOCK_USAGE_BEFORE_DROP block will be dropped in 'used' list)
|
|
105 |
*/
|
|
1
by brian
clean slate |
106 |
unsigned int first_block_usage; |
107 |
||
2318.6.24
by Olaf van der Spek
Refactor |
108 |
void reset_defaults(size_t block_size, size_t prealloc_size); |
2318.6.41
by Olaf van der Spek
Refactor |
109 |
unsigned char* alloc(size_t Size); |
1485
by Brian Aker
Updates to confine memroot |
110 |
void mark_blocks_free(); |
2318.6.24
by Olaf van der Spek
Refactor |
111 |
void* memdup(const void*, size_t); |
112 |
char* strdup(const char*); |
|
2148.7.9
by Brian Aker
Remove strdup |
113 |
|
2318.9.10
by Olaf van der Spek
Rename strmake to strdup (standard name) |
114 |
char* strdup(const char*, size_t); |
115 |
char* strdup(str_ref); |
|
2318.6.23
by Olaf van der Spek
Refactor |
116 |
void init(size_t block_size= ROOT_MIN_BLOCK_SIZE); |
1485
by Brian Aker
Updates to confine memroot |
117 |
|
2385.2.4
by Olaf van der Spek
cppcheck |
118 |
bool alloc_root_inited() const |
1487
by Brian Aker
More updates for memory::Root |
119 |
{
|
120 |
return min_malloc != 0; |
|
121 |
}
|
|
122 |
void free_root(myf MyFLAGS); |
|
2318.6.41
by Olaf van der Spek
Refactor |
123 |
void* multi_alloc(int unused, ...); |
2318.6.20
by Olaf van der Spek
Refactor |
124 |
|
125 |
void* calloc(size_t size) |
|
126 |
{
|
|
2318.6.40
by Olaf van der Spek
Refactor |
127 |
void* ptr= alloc(size); |
2318.6.20
by Olaf van der Spek
Refactor |
128 |
memset(ptr, 0, size); |
129 |
return ptr; |
|
130 |
}
|
|
1253.1.3
by Monty Taylor
MEM_ROOT == memory::Root |
131 |
};
|
492.1.1
by Monty Taylor
Moved MEM_ROOT functions into my_alloc.h. |
132 |
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
133 |
} /* namespace memory */ |
134 |
} /* namespace drizzled */ |
|
492.1.1
by Monty Taylor
Moved MEM_ROOT functions into my_alloc.h. |
135 |
|
2318.6.54
by Olaf van der Spek
Refactor |
136 |
inline void* operator new(size_t size, drizzled::memory::Root& root) |
137 |
{
|
|
138 |
return root.alloc(size); |
|
139 |
}
|
|
140 |
||
2318.6.58
by Olaf van der Spek
Refactor |
141 |
inline void* operator new[](size_t size, drizzled::memory::Root& root) |
142 |
{
|
|
143 |
return root.alloc(size); |
|
144 |
}
|
|
2318.6.73
by Olaf van der Spek
Refactor |
145 |
|
146 |
inline void operator delete(void*, drizzled::memory::Root&) |
|
147 |
{
|
|
148 |
}
|
|
149 |
||
150 |
inline void operator delete[](void*, drizzled::memory::Root&) |
|
151 |
{
|
|
152 |
}
|