~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/my_alloc.h

code clean move Item_func_num1 and Item_func_connection_id to functions directory

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
 
 * @file
18
 
 * @brief Memory root declarations
19
 
 */
20
 
 
21
 
#ifndef DRIZZLED_MEMORY_ROOT_H
22
 
#define DRIZZLED_MEMORY_ROOT_H
23
 
 
24
 
#include <cstddef>
25
 
 
26
 
#include <drizzled/definitions.h>
27
 
 
28
 
namespace drizzled
29
 
{
30
 
 
31
 
/**
32
 
 * @namespace drizzled::memory
33
 
 * Memory allocation utils
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.
38
 
 */
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
 
 
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
 
 
61
 
 
62
 
 
63
 
class Root
64
 
{
65
 
public:
66
 
 
67
 
  Root() :
68
 
    free(0),
69
 
    used(0),
70
 
    pre_alloc(0),
71
 
    min_malloc(0),
72
 
    block_size(0),
73
 
    block_num(0),
74
 
    first_block_usage(0),
75
 
    error_handler(0)
76
 
  { }
77
 
 
78
 
  Root(size_t block_size_arg)
79
 
  {
80
 
    free= used= pre_alloc= 0;
81
 
    min_malloc= 32;
82
 
    block_size= block_size_arg - memory::ROOT_MIN_BLOCK_SIZE;
83
 
    block_num= 4;                       /* We shift this with >>2 */
84
 
    first_block_usage= 0;
85
 
    error_handler= 0;
86
 
  }
87
 
 
88
 
  /**
89
 
   * blocks with free memory in it 
90
 
   */
91
 
  internal::UsedMemory *free;
92
 
 
93
 
  /**
94
 
   * blocks almost without free memory 
95
 
   */
96
 
  internal::UsedMemory *used;
97
 
 
98
 
  /**
99
 
   * preallocated block 
100
 
   */
101
 
  internal::UsedMemory *pre_alloc;
102
 
 
103
 
  /**
104
 
   * if block have less memory it will be put in 'used' list 
105
 
   */
 
16
/* 
 
17
   Data structures for mysys/my_alloc.c (root memory allocator)
 
18
*/
 
19
 
 
20
#ifndef _my_alloc_h
 
21
#define _my_alloc_h
 
22
 
 
23
#define ALLOC_MAX_BLOCK_TO_DROP                 4096
 
24
#define ALLOC_MAX_BLOCK_USAGE_BEFORE_DROP       10
 
25
 
 
26
typedef struct st_used_mem
 
27
{                                  /* struct for once_alloc (block) */
 
28
  struct st_used_mem *next;        /* Next block in use */
 
29
  unsigned int  left;              /* memory left in block  */
 
30
  unsigned int  size;              /* size of block */
 
31
} USED_MEM;
 
32
 
 
33
 
 
34
typedef struct st_mem_root
 
35
{
 
36
  USED_MEM *free;                  /* blocks with free memory in it */
 
37
  USED_MEM *used;                  /* blocks almost without free memory */
 
38
  USED_MEM *pre_alloc;             /* preallocated block */
 
39
  /* if block have less memory it will be put in 'used' list */
106
40
  size_t min_malloc;
107
 
 
108
 
  size_t block_size;         ///< initial block size
109
 
  unsigned int block_num;    ///< allocated blocks counter 
110
 
 
111
 
  /**
112
 
   * first free block in queue test counter (if it exceed
113
 
   * MAX_BLOCK_USAGE_BEFORE_DROP block will be dropped in 'used' list)
114
 
   */
 
41
  size_t block_size;               /* initial block size */
 
42
  unsigned int block_num;          /* allocated blocks counter */
 
43
  /* 
 
44
     first free block in queue test counter (if it exceed 
 
45
     MAX_BLOCK_USAGE_BEFORE_DROP block will be dropped in 'used' list)
 
46
  */
115
47
  unsigned int first_block_usage;
116
48
 
117
49
  void (*error_handler)(void);
118
 
  void reset_root_defaults(size_t block_size, size_t prealloc_size);
119
 
  void *alloc_root(size_t Size);
120
 
  void mark_blocks_free();
121
 
  void *memdup_root(const void *str, size_t len);
122
 
  char *strdup_root(const char *str);
123
 
  char *strmake_root(const char *str,size_t len);
124
 
  void init_alloc_root(size_t block_size= ROOT_MIN_BLOCK_SIZE);
125
 
 
126
 
  inline bool alloc_root_inited()
127
 
  {
128
 
    return min_malloc != 0;
129
 
  }
130
 
  void free_root(myf MyFLAGS);
131
 
  void *multi_alloc_root(int unused, ...);
132
 
};
133
 
 
134
 
} /* namespace memory */
135
 
} /* namespace drizzled */
136
 
 
137
 
#endif /* DRIZZLED_MEMORY_ROOT_H */
 
50
} MEM_ROOT;
 
51
#endif