~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/memory/root.h

  • Committer: Joe Daly
  • Date: 2010-05-27 02:59:16 UTC
  • mto: This revision was merged to the branch mainline in revision 1614.
  • Revision ID: skinny.moey@gmail.com-20100527025916-o4wieb1hxk2shq4u
add status_vars to scoreboard, initial pass

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
 */
16
20
 
17
21
#ifndef DRIZZLED_MEMORY_ROOT_H
18
22
#define DRIZZLED_MEMORY_ROOT_H
23
27
 
24
28
namespace drizzled
25
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
 */
26
39
namespace memory
27
40
{
28
41
 
50
63
class Root
51
64
{
52
65
public:
53
 
  /* blocks with free memory in it */
 
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
 
 
78
  /**
 
79
   * blocks with free memory in it 
 
80
   */
54
81
  internal::UsedMemory *free;
55
82
 
56
 
  /* blocks almost without free memory */
 
83
  /**
 
84
   * blocks almost without free memory 
 
85
   */
57
86
  internal::UsedMemory *used;
58
87
 
59
 
  /* preallocated block */
 
88
  /**
 
89
   * preallocated block 
 
90
   */
60
91
  internal::UsedMemory *pre_alloc;
61
92
 
62
 
  /* if block have less memory it will be put in 'used' list */
 
93
  /**
 
94
   * if block have less memory it will be put in 'used' list 
 
95
   */
63
96
  size_t min_malloc;
64
 
  size_t block_size;               /* initial block size */
65
 
  unsigned int block_num;          /* allocated blocks counter */
66
 
  /*
67
 
     first free block in queue test counter (if it exceed
68
 
     MAX_BLOCK_USAGE_BEFORE_DROP block will be dropped in 'used' list)
69
 
  */
 
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
   */
70
105
  unsigned int first_block_usage;
71
106
 
72
107
  void (*error_handler)(void);
 
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();
 
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);
 
115
 
 
116
  inline bool alloc_root_inited()
 
117
  {
 
118
    return min_malloc != 0;
 
119
  }
 
120
  void free_root(myf MyFLAGS);
 
121
  void *multi_alloc_root(int unused, ...);
 
122
 
73
123
};
74
124
 
75
 
inline static bool alloc_root_inited(Root *root)
76
 
{
77
 
  return root->min_malloc != 0;
78
 
}
79
 
 
80
 
void init_alloc_root(Root *mem_root,
81
 
                     size_t block_size= ROOT_MIN_BLOCK_SIZE);
82
 
void *alloc_root(Root *mem_root, size_t Size);
83
 
void *multi_alloc_root(Root *mem_root, ...);
84
 
void free_root(Root *root, myf MyFLAGS);
85
 
void set_prealloc_root(Root *root, char *ptr);
86
 
void reset_root_defaults(Root *mem_root, size_t block_size,
87
 
                         size_t prealloc_size);
88
 
char *strdup_root(Root *root,const char *str);
89
 
char *strmake_root(Root *root,const char *str,size_t len);
90
 
void *memdup_root(Root *root,const void *str, size_t len);
91
 
 
92
125
} /* namespace memory */
93
126
} /* namespace drizzled */
94
127