Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00021 #pragma once
00022
00023 #include <drizzled/common_fwd.h>
00024 #include <drizzled/definitions.h>
00025 #include <drizzled/util/data_ref.h>
00026 #include <drizzled/visibility.h>
00027
00028 namespace drizzled {
00029
00038 namespace memory {
00039
00040 static const int KEEP_PREALLOC= 1;
00041
00042 static const int MARK_BLOCKS_FREE= 2;
00043
00044 namespace internal
00045 {
00046 class UsedMemory
00047 {
00048 public:
00049 UsedMemory *next;
00050 size_t left;
00051 size_t size;
00052 };
00053 }
00054
00055 static const size_t ROOT_MIN_BLOCK_SIZE= (MALLOC_OVERHEAD + sizeof(internal::UsedMemory) + 8);
00056
00057 class DRIZZLED_API Root
00058 {
00059 public:
00060 Root() :
00061 free(0),
00062 used(0),
00063 pre_alloc(0),
00064 min_malloc(0),
00065 block_size(0),
00066 block_num(0),
00067 first_block_usage(0)
00068 { }
00069
00070 Root(size_t block_size_arg)
00071 {
00072 free= used= pre_alloc= 0;
00073 min_malloc= 32;
00074 block_size= block_size_arg - memory::ROOT_MIN_BLOCK_SIZE;
00075 block_num= 4;
00076 first_block_usage= 0;
00077 }
00078
00082 internal::UsedMemory *free;
00083
00087 internal::UsedMemory *used;
00088
00092 internal::UsedMemory *pre_alloc;
00093
00097 size_t min_malloc;
00098
00099 size_t block_size;
00100 unsigned int block_num;
00101
00106 unsigned int first_block_usage;
00107
00108 void reset_defaults(size_t block_size, size_t prealloc_size);
00109 unsigned char* alloc(size_t Size);
00110 void mark_blocks_free();
00111 void* memdup(const void*, size_t);
00112 char* strdup(const char*);
00113
00114 char* strdup(const char*, size_t);
00115 char* strdup(str_ref);
00116 void init(size_t block_size= ROOT_MIN_BLOCK_SIZE);
00117
00118 bool alloc_root_inited() const
00119 {
00120 return min_malloc != 0;
00121 }
00122 void free_root(myf MyFLAGS);
00123 void* multi_alloc(int unused, ...);
00124
00125 void* calloc(size_t size)
00126 {
00127 void* ptr= alloc(size);
00128 memset(ptr, 0, size);
00129 return ptr;
00130 }
00131 };
00132
00133 }
00134 }
00135
00136 inline void* operator new(size_t size, drizzled::memory::Root& root)
00137 {
00138 return root.alloc(size);
00139 }
00140
00141 inline void* operator new[](size_t size, drizzled::memory::Root& root)
00142 {
00143 return root.alloc(size);
00144 }
00145
00146 inline void operator delete(void*, drizzled::memory::Root&)
00147 {
00148 }
00149
00150 inline void operator delete[](void*, drizzled::memory::Root&)
00151 {
00152 }