~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/memory/root.h

  • Committer: lbieber
  • Date: 2010-01-21 18:21:39 UTC
  • mto: This revision was merged to the branch mainline in revision 1277.
  • Revision ID: lbieber@orisndriz08-20100121182139-h549us3gsysyyl0e
clean up japanese tests, remove tests that no longer apply.  In test-run.pl change mysql_version_id to drizzle_version_id

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
   You should have received a copy of the GNU General Public License
13
13
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
 
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
16
 
21
17
#ifndef DRIZZLED_MEMORY_ROOT_H
22
18
#define DRIZZLED_MEMORY_ROOT_H
25
21
 
26
22
#include <drizzled/definitions.h>
27
23
 
 
24
#if defined(__cplusplus)
 
25
extern "C" {
 
26
#endif
 
27
 
28
28
namespace drizzled
29
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
30
namespace memory
40
31
{
41
32
 
63
54
class Root
64
55
{
65
56
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
 
  ~Root();
89
 
 
90
 
  /**
91
 
   * blocks with free memory in it 
92
 
   */
 
57
  /* blocks with free memory in it */
93
58
  internal::UsedMemory *free;
94
59
 
95
 
  /**
96
 
   * blocks almost without free memory 
97
 
   */
 
60
  /* blocks almost without free memory */
98
61
  internal::UsedMemory *used;
99
62
 
100
 
  /**
101
 
   * preallocated block 
102
 
   */
 
63
  /* preallocated block */
103
64
  internal::UsedMemory *pre_alloc;
104
65
 
105
 
  /**
106
 
   * if block have less memory it will be put in 'used' list 
107
 
   */
 
66
  /* if block have less memory it will be put in 'used' list */
108
67
  size_t min_malloc;
109
 
 
110
 
  size_t block_size;         ///< initial block size
111
 
  unsigned int block_num;    ///< allocated blocks counter 
112
 
 
113
 
  /**
114
 
   * first free block in queue test counter (if it exceed
115
 
   * MAX_BLOCK_USAGE_BEFORE_DROP block will be dropped in 'used' list)
116
 
   */
 
68
  size_t block_size;               /* initial block size */
 
69
  unsigned int block_num;          /* allocated blocks counter */
 
70
  /*
 
71
     first free block in queue test counter (if it exceed
 
72
     MAX_BLOCK_USAGE_BEFORE_DROP block will be dropped in 'used' list)
 
73
  */
117
74
  unsigned int first_block_usage;
118
75
 
119
76
  void (*error_handler)(void);
120
 
  void reset_root_defaults(size_t block_size, size_t prealloc_size);
121
 
  void *alloc_root(size_t Size);
122
 
  void mark_blocks_free();
123
 
  void *memdup_root(const void *str, size_t len);
124
 
  char *strdup_root(const char *str);
125
 
  char *strmake_root(const char *str,size_t len);
126
 
  void init_alloc_root(size_t block_size= ROOT_MIN_BLOCK_SIZE);
127
 
 
128
 
  inline bool alloc_root_inited()
129
 
  {
130
 
    return min_malloc != 0;
131
 
  }
132
 
  void free_root(myf MyFLAGS);
133
 
  void *multi_alloc_root(int unused, ...);
134
77
};
135
78
 
136
 
} /* namespace memory */
137
 
} /* namespace drizzled */
138
 
 
 
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,
 
91
                         size_t prealloc_size);
 
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
}
 
98
 
 
99
#if defined(__cplusplus)
 
100
}
 
101
#endif
139
102
#endif /* DRIZZLED_MEMORY_ROOT_H */