~drizzle-trunk/drizzle/development

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
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
1241.9.56 by Monty Taylor
More mysys cleaning.
21
#ifndef DRIZZLED_MEMORY_ROOT_H
22
#define DRIZZLED_MEMORY_ROOT_H
1 by brian
clean slate
23
1253.1.1 by Monty Taylor
First bits of namespacing. Ugh. Why do I do this to myself.
24
#include <cstddef>
1241.9.56 by Monty Taylor
More mysys cleaning.
25
575.1.6 by Monty Taylor
Cleaned up some headers for PCH.
26
#include <drizzled/definitions.h>
27
1253.1.1 by Monty Taylor
First bits of namespacing. Ugh. Why do I do this to myself.
28
namespace drizzled
29
{
1441.2.3 by Tim Martin
Updating existing comments to doxygen format
30
31
/**
32
 * @namespace drizzled::memory
33
 * Memory allocation utils
1441.2.5 by Tim Martin
More doxygen commenting
34
 *
35
 * NB: This namespace documentation may not seem very useful, but without a
36
 * comment on the namespace Doxygen won't extract any documentation for
37
 * namespace members.
1441.2.3 by Tim Martin
Updating existing comments to doxygen format
38
 */
1253.1.1 by Monty Taylor
First bits of namespacing. Ugh. Why do I do this to myself.
39
namespace memory
40
{
41
42
static const int KEEP_PREALLOC= 1;
43
/* move used to free list and reuse them */
44
static const int MARK_BLOCKS_FREE= 2;
45
1253.1.2 by Monty Taylor
We have init_sql_alloc and init_alloc_root - and I can't tell the difference.
46
namespace internal
47
{
48
49
class UsedMemory
50
{			   /* struct for once_alloc (block) */
51
public:
52
  UsedMemory *next;	   /* Next block in use */
53
  size_t left;		   /* memory left in block  */            
54
  size_t size;		   /* size of block */
55
};
56
57
}
58
59
static const size_t ROOT_MIN_BLOCK_SIZE= (MALLOC_OVERHEAD + sizeof(internal::UsedMemory) + 8);
60
1253.1.3 by Monty Taylor
MEM_ROOT == memory::Root
61
62
63
class Root
1 by brian
clean slate
64
{
1253.1.3 by Monty Taylor
MEM_ROOT == memory::Root
65
public:
1485 by Brian Aker
Updates to confine memroot
66
67
  Root() { }
68
  Root(size_t block_size_arg)
69
  {
70
    free= used= pre_alloc= 0;
71
    min_malloc= 32;
72
    block_size= block_size_arg - memory::ROOT_MIN_BLOCK_SIZE;
73
    error_handler= 0;
74
    block_num= 4;			/* We shift this with >>2 */
75
    first_block_usage= 0;
76
  }
77
1441.2.1 by Tim Martin
Reformatting some memory/root.h comments for doxygen
78
  /**
79
   * blocks with free memory in it 
80
   */
1253.1.3 by Monty Taylor
MEM_ROOT == memory::Root
81
  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.
82
1441.2.1 by Tim Martin
Reformatting some memory/root.h comments for doxygen
83
  /**
84
   * blocks almost without free memory 
85
   */
1253.1.3 by Monty Taylor
MEM_ROOT == memory::Root
86
  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.
87
1441.2.1 by Tim Martin
Reformatting some memory/root.h comments for doxygen
88
  /**
89
   * preallocated block 
90
   */
1253.1.3 by Monty Taylor
MEM_ROOT == memory::Root
91
  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.
92
1441.2.1 by Tim Martin
Reformatting some memory/root.h comments for doxygen
93
  /**
94
   * if block have less memory it will be put in 'used' list 
95
   */
1 by brian
clean slate
96
  size_t min_malloc;
1441.2.1 by Tim Martin
Reformatting some memory/root.h comments for doxygen
97
98
  size_t block_size;         ///< initial block size
99
  unsigned int block_num;    ///< allocated blocks counter 
100
101
  /**
102
   * first free block in queue test counter (if it exceed
103
   * MAX_BLOCK_USAGE_BEFORE_DROP block will be dropped in 'used' list)
104
   */
1 by brian
clean slate
105
  unsigned int first_block_usage;
106
107
  void (*error_handler)(void);
1485 by Brian Aker
Updates to confine memroot
108
  void reset_root_defaults(size_t block_size, size_t prealloc_size);
109
  void *alloc_root(size_t Size);
110
  void mark_blocks_free();
1487 by Brian Aker
More updates for memory::Root
111
  void *memdup_root(const void *str, size_t len);
112
  char *strdup_root(const char *str);
113
  char *strmake_root(const char *str,size_t len);
114
  void init_alloc_root(size_t block_size= ROOT_MIN_BLOCK_SIZE);
1485 by Brian Aker
Updates to confine memroot
115
1487 by Brian Aker
More updates for memory::Root
116
  inline bool alloc_root_inited()
117
  {
118
    return min_malloc != 0;
119
  }
120
  void free_root(myf MyFLAGS);
1253.1.3 by Monty Taylor
MEM_ROOT == memory::Root
121
};
492.1.1 by Monty Taylor
Moved MEM_ROOT functions into my_alloc.h.
122
1253.1.3 by Monty Taylor
MEM_ROOT == memory::Root
123
void *multi_alloc_root(Root *mem_root, ...);
124
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
125
} /* namespace memory */
126
} /* namespace drizzled */
492.1.1 by Monty Taylor
Moved MEM_ROOT functions into my_alloc.h.
127
1241.9.56 by Monty Taylor
More mysys cleaning.
128
#endif /* DRIZZLED_MEMORY_ROOT_H */