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
|
|
14 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
15 |
||
16 |
||
1241.9.56
by Monty Taylor
More mysys cleaning. |
17 |
#ifndef DRIZZLED_MEMORY_ROOT_H
|
18 |
#define DRIZZLED_MEMORY_ROOT_H
|
|
1
by brian
clean slate |
19 |
|
1253.1.1
by Monty Taylor
First bits of namespacing. Ugh. Why do I do this to myself. |
20 |
#include <cstddef> |
1241.9.56
by Monty Taylor
More mysys cleaning. |
21 |
|
575.1.6
by Monty Taylor
Cleaned up some headers for PCH. |
22 |
#include <drizzled/definitions.h> |
23 |
||
492.1.3
by Monty Taylor
Merged from Lee. |
24 |
#if defined(__cplusplus)
|
25 |
extern "C" { |
|
26 |
#endif
|
|
27 |
||
1253.1.1
by Monty Taylor
First bits of namespacing. Ugh. Why do I do this to myself. |
28 |
namespace drizzled |
29 |
{
|
|
30 |
namespace memory |
|
31 |
{
|
|
32 |
||
33 |
static const int KEEP_PREALLOC= 1; |
|
34 |
/* move used to free list and reuse them */
|
|
35 |
static const int MARK_BLOCKS_FREE= 2; |
|
36 |
||
1253.1.2
by Monty Taylor
We have init_sql_alloc and init_alloc_root - and I can't tell the difference. |
37 |
namespace internal |
38 |
{
|
|
39 |
||
40 |
class UsedMemory |
|
41 |
{ /* struct for once_alloc (block) */ |
|
42 |
public: |
|
43 |
UsedMemory *next; /* Next block in use */ |
|
44 |
size_t left; /* memory left in block */ |
|
45 |
size_t size; /* size of block */ |
|
46 |
};
|
|
47 |
||
48 |
}
|
|
49 |
||
50 |
static const size_t ROOT_MIN_BLOCK_SIZE= (MALLOC_OVERHEAD + sizeof(internal::UsedMemory) + 8); |
|
51 |
||
1253.1.3
by Monty Taylor
MEM_ROOT == memory::Root |
52 |
|
53 |
||
54 |
class Root |
|
1
by brian
clean slate |
55 |
{
|
1253.1.3
by Monty Taylor
MEM_ROOT == memory::Root |
56 |
public: |
1253.1.2
by Monty Taylor
We have init_sql_alloc and init_alloc_root - and I can't tell the difference. |
57 |
/* blocks with free memory in it */
|
1253.1.3
by Monty Taylor
MEM_ROOT == memory::Root |
58 |
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. |
59 |
|
60 |
/* blocks almost without free memory */
|
|
1253.1.3
by Monty Taylor
MEM_ROOT == memory::Root |
61 |
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. |
62 |
|
63 |
/* preallocated block */
|
|
1253.1.3
by Monty Taylor
MEM_ROOT == memory::Root |
64 |
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. |
65 |
|
1
by brian
clean slate |
66 |
/* if block have less memory it will be put in 'used' list */
|
67 |
size_t min_malloc; |
|
68 |
size_t block_size; /* initial block size */ |
|
69 |
unsigned int block_num; /* allocated blocks counter */ |
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
70 |
/*
|
71 |
first free block in queue test counter (if it exceed
|
|
1
by brian
clean slate |
72 |
MAX_BLOCK_USAGE_BEFORE_DROP block will be dropped in 'used' list)
|
73 |
*/
|
|
74 |
unsigned int first_block_usage; |
|
75 |
||
76 |
void (*error_handler)(void); |
|
1253.1.3
by Monty Taylor
MEM_ROOT == memory::Root |
77 |
};
|
492.1.1
by Monty Taylor
Moved MEM_ROOT functions into my_alloc.h. |
78 |
|
1253.1.3
by Monty Taylor
MEM_ROOT == memory::Root |
79 |
inline static bool alloc_root_inited(Root *root) |
1253.1.1
by Monty Taylor
First bits of namespacing. Ugh. Why do I do this to myself. |
80 |
{
|
81 |
return root->min_malloc != 0; |
|
82 |
}
|
|
83 |
||
1253.1.3
by Monty Taylor
MEM_ROOT == memory::Root |
84 |
void init_alloc_root(Root *mem_root, |
85 |
size_t block_size= ROOT_MIN_BLOCK_SIZE); |
|
86 |
void *alloc_root(Root *mem_root, size_t Size); |
|
87 |
void *multi_alloc_root(Root *mem_root, ...); |
|
88 |
void free_root(Root *root, myf MyFLAGS); |
|
89 |
void set_prealloc_root(Root *root, char *ptr); |
|
90 |
void reset_root_defaults(Root *mem_root, size_t block_size, |
|
492.1.1
by Monty Taylor
Moved MEM_ROOT functions into my_alloc.h. |
91 |
size_t prealloc_size); |
1253.1.3
by Monty Taylor
MEM_ROOT == memory::Root |
92 |
char *strdup_root(Root *root,const char *str); |
93 |
char *strmake_root(Root *root,const char *str,size_t len); |
|
94 |
void *memdup_root(Root *root,const void *str, size_t len); |
|
95 |
||
96 |
}
|
|
97 |
}
|
|
492.1.1
by Monty Taylor
Moved MEM_ROOT functions into my_alloc.h. |
98 |
|
492.1.3
by Monty Taylor
Merged from Lee. |
99 |
#if defined(__cplusplus)
|
100 |
}
|
|
101 |
#endif
|
|
1241.9.56
by Monty Taylor
More mysys cleaning. |
102 |
#endif /* DRIZZLED_MEMORY_ROOT_H */ |