allocated bigger blocks if it needed

include/my_sys.h:
  memory root structures definition put in one file
include/mysql.h:
  memory root structures definition put in one file
This commit is contained in:
unknown 2002-04-13 12:08:12 +03:00
commit f095ef5dc2
4 changed files with 49 additions and 45 deletions

View file

@ -29,6 +29,7 @@ void init_alloc_root(MEM_ROOT *mem_root, uint block_size,
mem_root->min_malloc=32;
mem_root->block_size=block_size-MALLOC_OVERHEAD-sizeof(USED_MEM)-8;
mem_root->error_handler=0;
mem_root->block_num= 0;
#if !(defined(HAVE_purify) && defined(EXTRA_DEBUG))
if (pre_alloc_size)
{
@ -61,25 +62,20 @@ gptr alloc_root(MEM_ROOT *mem_root,unsigned int Size)
mem_root->used=next;
return (gptr) (((char*) next)+ALIGN_SIZE(sizeof(USED_MEM)));
#else
uint get_size,max_left;
uint get_size, block_size;
gptr point;
reg1 USED_MEM *next;
reg2 USED_MEM **prev;
Size= ALIGN_SIZE(Size);
prev= &mem_root->free;
max_left=0;
for (next= *prev ; next && next->left < Size ; next= next->next)
{
if (next->left > max_left)
max_left=next->left;
prev= &next->next;
}
if (! next)
{ /* Time to alloc new block */
block_size= mem_root->block_size*((mem_root->block_num>>2)+1);
get_size= Size+ALIGN_SIZE(sizeof(USED_MEM));
if (max_left*4 < mem_root->block_size && get_size < mem_root->block_size)
get_size=mem_root->block_size; /* Normal alloc */
get_size= max(get_size, block_size);
if (!(next = (USED_MEM*) my_malloc(get_size,MYF(MY_WME))))
{
@ -87,6 +83,7 @@ gptr alloc_root(MEM_ROOT *mem_root,unsigned int Size)
(*mem_root->error_handler)();
return((gptr) 0); /* purecov: inspected */
}
mem_root->block_num++;
next->next= *prev;
next->size= get_size;
next->left= get_size-ALIGN_SIZE(sizeof(USED_MEM));
@ -165,7 +162,10 @@ void free_root(MEM_ROOT *root, myf MyFlags)
root->free=root->pre_alloc;
root->free->left=root->pre_alloc->size-ALIGN_SIZE(sizeof(USED_MEM));
root->free->next=0;
root->block_num= 1;
}
else
root->block_num= 0;
DBUG_VOID_RETURN;
}