Commit 446ad272 authored by bell@sanja.is.com.ua's avatar bell@sanja.is.com.ua
Browse files

collision resolving

parents e5866a7a 8dc64567
Loading
Loading
Loading
Loading

include/my_alloc.h

0 → 100644
+39 −0
Original line number Diff line number Diff line
/* Copyright (C) 2000 MySQL AB

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */

/* 
   Data structures for mysys/my_alloc.c (root memory allocator)
*/

#ifndef ST_USED_MEM_DEFINED
#define ST_USED_MEM_DEFINED
typedef struct st_used_mem {	   /* struct for once_alloc (block) */
  struct st_used_mem *next;	   /* Next block in use */
  unsigned int	left;		   /* memory left in block  */
  unsigned int	size;		   /* size of block */
} USED_MEM;
typedef struct st_mem_root {
  USED_MEM *free;                  /* blocks with free memory in it */
  USED_MEM *used;                  /* blocks almost without free memory */
  USED_MEM *pre_alloc;             /* preallocated block */
  /* if block have less memory it will be put in 'used' list*/
  unsigned int	min_malloc;
  unsigned int	block_size;        /* initial block size */
  unsigned int	block_num;         /* allocated blocks counter */

  void (*error_handler)(void);
} MEM_ROOT;
#endif
+1 −20
Original line number Diff line number Diff line
@@ -464,26 +464,7 @@ typedef struct st_changeable_var {
} CHANGEABLE_VAR;


/* structs for alloc_root */

#ifndef ST_USED_MEM_DEFINED
#define ST_USED_MEM_DEFINED
typedef struct st_used_mem {			/* struct for once_alloc */
  struct st_used_mem *next;			/* Next block in use */
  unsigned int left;				/* memory left in block  */
  unsigned int size;				/* Size of block */
} USED_MEM;

typedef struct st_mem_root {
  USED_MEM *free;
  USED_MEM *used;
  USED_MEM *pre_alloc;
  unsigned int	min_malloc;
  unsigned int	block_size;

  void (*error_handler)(void);
} MEM_ROOT;
#endif
#include "my_alloc.h"

	/* Prototypes for mysys and my_func functions */

+1 −17
Original line number Diff line number Diff line
@@ -100,23 +100,7 @@ typedef struct st_mysql_rows {

typedef MYSQL_ROWS *MYSQL_ROW_OFFSET;	/* offset to current row */

#ifndef ST_USED_MEM_DEFINED
#define ST_USED_MEM_DEFINED
typedef struct st_used_mem {			/* struct for once_alloc */
  struct st_used_mem *next;			/* Next block in use */
  unsigned int	left;				/* memory left in block  */
  unsigned int	size;				/* size of block */
} USED_MEM;
typedef struct st_mem_root {
  USED_MEM *free;
  USED_MEM *used;
  USED_MEM *pre_alloc;
  unsigned int	min_malloc;
  unsigned int	block_size;

  void (*error_handler)(void);
} MEM_ROOT;
#endif
#include "my_alloc.h"

typedef struct st_mysql_data {
  my_ulonglong rows;
+8 −8
Original line number Diff line number Diff line
@@ -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;
}