~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/my_alloc.h

  • Committer: Padraig O'Sullivan
  • Date: 2009-06-29 17:24:02 UTC
  • mto: This revision was merged to the branch mainline in revision 1081.
  • Revision ID: osullivan.padraig@gmail.com-20090629172402-9c5n1kr7ry7xgau7
Removed the dependency on knowing the position of an I_S table in the
schema_tables array defined in show.cc. This issue crops up in
prepare_schema_table. An issue with my design is that it increases the time
complexity from O(1) to O(n) in numerous places to determine an I_S table to
work on since we don't have an explicit index into the array and instead
need to search by name. However, as n is the number of I_S tables and this
number is quite small (at the moment n is < 30), we don't see this causing
any issue. This design makes the code much more maintainable and easier to
understand. Previously, modifying anything to do with the I_S tables meant
having to tip-toe around the issue of hard-coded indexes into the
schema_tables array.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
   along with this program; if not, write to the Free Software
14
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
 
/* 
 
16
/*
17
17
   Data structures for mysys/my_alloc.c (root memory allocator)
18
18
*/
19
19
 
20
20
#ifndef _my_alloc_h
21
21
#define _my_alloc_h
22
22
 
 
23
#include <stddef.h>
 
24
#include <drizzled/definitions.h>
 
25
 
 
26
#if defined(__cplusplus)
 
27
extern "C" {
 
28
#endif
 
29
 
23
30
#define ALLOC_MAX_BLOCK_TO_DROP                 4096
24
31
#define ALLOC_MAX_BLOCK_USAGE_BEFORE_DROP       10
25
32
 
40
47
  size_t min_malloc;
41
48
  size_t block_size;               /* initial block size */
42
49
  unsigned int block_num;          /* allocated blocks counter */
43
 
  /* 
44
 
     first free block in queue test counter (if it exceed 
 
50
  /*
 
51
     first free block in queue test counter (if it exceed
45
52
     MAX_BLOCK_USAGE_BEFORE_DROP block will be dropped in 'used' list)
46
53
  */
47
54
  unsigned int first_block_usage;
48
55
 
49
56
  void (*error_handler)(void);
50
57
} MEM_ROOT;
 
58
 
 
59
void init_alloc_root(MEM_ROOT *mem_root, size_t block_size,
 
60
                     size_t pre_alloc_size);
 
61
void *alloc_root(MEM_ROOT *mem_root, size_t Size);
 
62
void *multi_alloc_root(MEM_ROOT *mem_root, ...);
 
63
void free_root(MEM_ROOT *root, myf MyFLAGS);
 
64
void set_prealloc_root(MEM_ROOT *root, char *ptr);
 
65
void reset_root_defaults(MEM_ROOT *mem_root, size_t block_size,
 
66
                         size_t prealloc_size);
 
67
char *strdup_root(MEM_ROOT *root,const char *str);
 
68
char *strmake_root(MEM_ROOT *root,const char *str,size_t len);
 
69
void *memdup_root(MEM_ROOT *root,const void *str, size_t len);
 
70
 
 
71
#if defined(__cplusplus)
 
72
}
 
73
#endif
51
74
#endif