~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/memory/root.h

  • Committer: Monty Taylor
  • Date: 2009-12-25 08:08:25 UTC
  • mto: This revision was merged to the branch mainline in revision 1255.
  • Revision ID: mordred@inaugust.com-20091225080825-r7qmhm2mswl0c4li
We have init_sql_alloc and init_alloc_root - and I can't tell the difference.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
/* move used to free list and reuse them */
35
35
static const int MARK_BLOCKS_FREE= 2;
36
36
 
37
 
}
38
 
}
39
 
 
40
 
#define ALLOC_ROOT_MIN_BLOCK_SIZE (MALLOC_OVERHEAD + sizeof(USED_MEM) + 8)
41
 
#define ALLOC_MAX_BLOCK_TO_DROP                 4096
42
 
#define ALLOC_MAX_BLOCK_USAGE_BEFORE_DROP       10
43
 
 
44
 
typedef struct st_used_mem
45
 
{                                  /* struct for once_alloc (block) */
46
 
  struct st_used_mem *next;        /* Next block in use */
47
 
  size_t left;                     /* memory left in block  */            
48
 
  size_t size;                     /* size of block */
49
 
} USED_MEM;
 
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
 
50
55
 
51
56
 
52
57
typedef struct st_mem_root
53
58
{
54
 
  USED_MEM *free;                  /* blocks with free memory in it */
55
 
  USED_MEM *used;                  /* blocks almost without free memory */
56
 
  USED_MEM *pre_alloc;             /* preallocated block */
 
59
  /* blocks with free memory in it */
 
60
  drizzled::memory::internal::UsedMemory *free;
 
61
 
 
62
  /* blocks almost without free memory */
 
63
  drizzled::memory::internal::UsedMemory *used;
 
64
 
 
65
  /* preallocated block */
 
66
  drizzled::memory::internal::UsedMemory *pre_alloc;
 
67
 
57
68
  /* if block have less memory it will be put in 'used' list */
58
69
  size_t min_malloc;
59
70
  size_t block_size;               /* initial block size */
72
83
  return root->min_malloc != 0;
73
84
}
74
85
 
75
 
void init_alloc_root(MEM_ROOT *mem_root, size_t block_size,
76
 
                     size_t pre_alloc_size);
 
86
void init_alloc_root(MEM_ROOT *mem_root,
 
87
                     size_t block_size= drizzled::memory::ROOT_MIN_BLOCK_SIZE);
77
88
void *alloc_root(MEM_ROOT *mem_root, size_t Size);
78
89
void *multi_alloc_root(MEM_ROOT *mem_root, ...);
79
90
void free_root(MEM_ROOT *root, myf MyFLAGS);