~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/memory/root.cc

  • Committer: Monty Taylor
  • Date: 2009-12-25 08:50:15 UTC
  • mto: This revision was merged to the branch mainline in revision 1255.
  • Revision ID: mordred@inaugust.com-20091225085015-83sux5qsvy312gew
MEM_ROOT == memory::Root

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#include <algorithm>
22
22
 
23
23
using namespace std;
24
 
using namespace drizzled;
 
24
 
 
25
namespace drizzled
 
26
{
25
27
 
26
28
static const unsigned int MAX_BLOCK_TO_DROP= 4096;
27
29
static const unsigned int MAX_BLOCK_USAGE_BEFORE_DROP= 10;
30
32
  Initialize memory root
31
33
 
32
34
  SYNOPSIS
33
 
    init_alloc_root()
 
35
    memory::init_alloc_root()
34
36
      mem_root       - memory root to initialize
35
37
      block_size     - size of chunks (blocks) used for memory allocation
36
38
                       (It is external size of chunk i.e. it should include
45
47
    reported as error in first alloc_root() on this memory root.
46
48
*/
47
49
 
48
 
void init_alloc_root(MEM_ROOT *mem_root, size_t block_size)
 
50
void memory::init_alloc_root(memory::Root *mem_root, size_t block_size)
49
51
{
50
52
  mem_root->free= mem_root->used= mem_root->pre_alloc= 0;
51
53
  mem_root->min_malloc= 32;
75
77
    before allocation.
76
78
*/
77
79
 
78
 
void reset_root_defaults(MEM_ROOT *mem_root, size_t block_size,
79
 
                         size_t pre_alloc_size)
 
80
void memory::reset_root_defaults(memory::Root *mem_root, size_t block_size,
 
81
                                 size_t pre_alloc_size)
80
82
{
81
83
  assert(alloc_root_inited(mem_root));
82
84
 
130
132
}
131
133
 
132
134
 
133
 
void *alloc_root(MEM_ROOT *mem_root, size_t length)
 
135
void *memory::alloc_root(memory::Root *mem_root, size_t length)
134
136
{
135
137
  size_t get_size, block_size;
136
138
  unsigned char* point;
205
207
    in case of success or NULL if out of memory.
206
208
*/
207
209
 
208
 
void *multi_alloc_root(MEM_ROOT *root, ...)
 
210
void *memory::multi_alloc_root(memory::Root *root, ...)
209
211
{
210
212
  va_list args;
211
213
  char **ptr, *start, *res;
220
222
  }
221
223
  va_end(args);
222
224
 
223
 
  if (!(start= (char*) alloc_root(root, tot_length)))
 
225
  if (!(start= (char*) memory::alloc_root(root, tot_length)))
224
226
    return(0);
225
227
 
226
228
  va_start(args, root);
239
241
 
240
242
/* Mark all data in blocks free for reusage */
241
243
 
242
 
static inline void mark_blocks_free(MEM_ROOT* root)
 
244
static inline void mark_blocks_free(memory::Root* root)
243
245
{
244
246
  memory::internal::UsedMemory *next;
245
247
  memory::internal::UsedMemory **last;
269
271
 
270
272
 
271
273
/*
272
 
  Deallocate everything used by alloc_root or just move
 
274
  Deallocate everything used by memory::alloc_root or just move
273
275
  used blocks to free list if called with MY_USED_TO_FREE
274
276
 
275
277
  SYNOPSIS
287
289
    It's also safe to call this multiple times with the same mem_root.
288
290
*/
289
291
 
290
 
void free_root(MEM_ROOT *root, myf MyFlags)
 
292
void memory::free_root(memory::Root *root, myf MyFlags)
291
293
{
292
294
  memory::internal::UsedMemory *next,*old;
293
295
 
328
330
  Find block that contains an object and set the pre_alloc to it
329
331
*/
330
332
 
331
 
void set_prealloc_root(MEM_ROOT *root, char *ptr)
 
333
void memory::set_prealloc_root(memory::Root *root, char *ptr)
332
334
{
333
335
  memory::internal::UsedMemory *next;
334
336
  for (next=root->used; next ; next=next->next)
350
352
}
351
353
 
352
354
 
353
 
char *strdup_root(MEM_ROOT *root, const char *str)
 
355
char *memory::strdup_root(memory::Root *root, const char *str)
354
356
{
355
357
  return strmake_root(root, str, strlen(str));
356
358
}
357
359
 
358
360
 
359
 
char *strmake_root(MEM_ROOT *root, const char *str, size_t len)
 
361
char *memory::strmake_root(memory::Root *root, const char *str, size_t len)
360
362
{
361
363
  char *pos;
362
 
  if ((pos=(char *)alloc_root(root,len+1)))
 
364
  if ((pos=(char *)memory::alloc_root(root,len+1)))
363
365
  {
364
366
    memcpy(pos,str,len);
365
367
    pos[len]=0;
368
370
}
369
371
 
370
372
 
371
 
void *memdup_root(MEM_ROOT *root, const void *str, size_t len)
 
373
void *memory::memdup_root(memory::Root *root, const void *str, size_t len)
372
374
{
373
375
  void *pos;
374
 
  if ((pos=alloc_root(root,len)))
 
376
  if ((pos=memory::alloc_root(root,len)))
375
377
    memcpy(pos,str,len);
376
378
  return pos;
377
379
}
 
380
 
 
381
} /* namespace drizzled */