~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/memory/root.h

Remove PLUGIN and MODULES.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
   along with this program; if not, write to the Free Software
14
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
 
/*
17
 
   Data structures for mysys/my_alloc.c (root memory allocator)
18
 
*/
19
 
 
20
 
#ifndef MYSYS_MY_ALLOC_H
21
 
#define MYSYS_MY_ALLOC_H
22
 
 
23
 
#include <stddef.h>
 
16
 
 
17
#ifndef DRIZZLED_MEMORY_ROOT_H
 
18
#define DRIZZLED_MEMORY_ROOT_H
 
19
 
 
20
#include <cstddef>
 
21
 
24
22
#include <drizzled/definitions.h>
25
23
 
26
24
#if defined(__cplusplus)
27
25
extern "C" {
28
26
#endif
29
27
 
30
 
#define ALLOC_MAX_BLOCK_TO_DROP                 4096
31
 
#define ALLOC_MAX_BLOCK_USAGE_BEFORE_DROP       10
32
 
 
33
 
typedef struct st_used_mem
34
 
{                                  /* struct for once_alloc (block) */
35
 
  struct st_used_mem *next;        /* Next block in use */
36
 
  size_t left;                     /* memory left in block  */            
37
 
  size_t size;                     /* size of block */
38
 
} USED_MEM;
39
 
 
40
 
 
41
 
typedef struct st_mem_root
42
 
{
43
 
  USED_MEM *free;                  /* blocks with free memory in it */
44
 
  USED_MEM *used;                  /* blocks almost without free memory */
45
 
  USED_MEM *pre_alloc;             /* preallocated block */
 
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
 
 
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
 
 
52
 
 
53
 
 
54
class Root
 
55
{
 
56
public:
 
57
  /* blocks with free memory in it */
 
58
  internal::UsedMemory *free;
 
59
 
 
60
  /* blocks almost without free memory */
 
61
  internal::UsedMemory *used;
 
62
 
 
63
  /* preallocated block */
 
64
  internal::UsedMemory *pre_alloc;
 
65
 
46
66
  /* if block have less memory it will be put in 'used' list */
47
67
  size_t min_malloc;
48
68
  size_t block_size;               /* initial block size */
54
74
  unsigned int first_block_usage;
55
75
 
56
76
  void (*error_handler)(void);
57
 
} MEM_ROOT;
58
 
 
59
 
void init_alloc_root(MEM_ROOT *mem_root, size_t block_size,
60
 
                     size_t pre_alloc_size);
61
 
void *alloc_root(MEM_ROOT *mem_root, size_t Size);
62
 
void *multi_alloc_root(MEM_ROOT *mem_root, ...);
63
 
void free_root(MEM_ROOT *root, myf MyFLAGS);
64
 
void set_prealloc_root(MEM_ROOT *root, char *ptr);
65
 
void reset_root_defaults(MEM_ROOT *mem_root, size_t block_size,
 
77
};
 
78
 
 
79
inline static bool alloc_root_inited(Root *root)
 
80
{
 
81
  return root->min_malloc != 0;
 
82
}
 
83
 
 
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,
66
91
                         size_t prealloc_size);
67
 
char *strdup_root(MEM_ROOT *root,const char *str);
68
 
char *strmake_root(MEM_ROOT *root,const char *str,size_t len);
69
 
void *memdup_root(MEM_ROOT *root,const void *str, size_t len);
 
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
}
70
98
 
71
99
#if defined(__cplusplus)
72
100
}
73
101
#endif
74
 
#endif /* MYSYS_MY_ALLOC_H */
 
102
#endif /* DRIZZLED_MEMORY_ROOT_H */