~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/memory/root.cc

  • Committer: Olaf van der Spek
  • Date: 2011-06-21 18:18:14 UTC
  • mto: This revision was merged to the branch mainline in revision 2346.
  • Revision ID: olafvdspek@gmail.com-20110621181814-4wsfwjgbw49tzq1e
Refactor

Show diffs side-by-side

added added

removed removed

Lines of Context:
137
137
 * @todo Would this be more suitable as a member function on the
138
138
 * Root class?
139
139
 */
140
 
void* Root::alloc_root(size_t length)
 
140
void* Root::alloc(size_t length)
141
141
{
142
142
  internal::UsedMemory *next= NULL;
143
 
  internal::UsedMemory **prev;
144
143
  assert(alloc_root_inited());
145
144
 
146
145
  length= ALIGN_SIZE(length);
147
 
  if ((*(prev= &this->free)) != NULL)
 
146
  internal::UsedMemory **prev= &this->free;
 
147
  if (*prev)
148
148
  {
149
149
    if ((*prev)->left < length &&
150
150
        this->first_block_usage++ >= MAX_BLOCK_USAGE_BEFORE_DROP &&
156
156
      this->used= next;
157
157
      this->first_block_usage= 0;
158
158
    }
159
 
    for (next= *prev ; next && next->left < length ; next= next->next)
 
159
    for (next= *prev; next && next->left < length; next= next->next)
160
160
      prev= &next->next;
161
161
  }
162
162
  if (! next)
163
163
  {                                             /* Time to alloc new block */
164
 
    size_t get_size, tmp_block_size;
165
 
 
166
 
    tmp_block_size= this->block_size * (this->block_num >> 2);
167
 
    get_size= length+ALIGN_SIZE(sizeof(internal::UsedMemory));
 
164
    size_t tmp_block_size= this->block_size * (this->block_num >> 2);
 
165
    size_t get_size= length+ALIGN_SIZE(sizeof(internal::UsedMemory));
168
166
    get_size= max(get_size, tmp_block_size);
169
167
 
170
168
    next = static_cast<internal::UsedMemory *>(malloc(get_size));
290
288
 */
291
289
void Root::free_root(myf MyFlags)
292
290
{
293
 
  internal::UsedMemory *next,*old;
294
 
 
295
291
  if (MyFlags & MARK_BLOCKS_FREE)
296
292
  {
297
293
    this->mark_blocks_free();
300
296
  if (!(MyFlags & KEEP_PREALLOC))
301
297
    this->pre_alloc=0;
302
298
 
303
 
  for (next=this->used; next ;)
 
299
  for (internal::UsedMemory* next= this->used; next;)
304
300
  {
305
 
    old=next; next= next->next ;
 
301
    internal::UsedMemory* old =next; 
 
302
    next= next->next;
306
303
    if (old != this->pre_alloc)
307
304
      std::free(old);
308
305
  }
309
 
  for (next=this->free ; next ;)
 
306
  for (internal::UsedMemory* next=this->free; next;)
310
307
  {
311
 
    old=next; next= next->next;
 
308
    internal::UsedMemory* old= next; 
 
309
    next= next->next;
312
310
    if (old != this->pre_alloc)
313
311
      std::free(old);
314
312
  }