#include "mem0mem.h"#include "mach0data.h"#include "buf0buf.h"#include "btr0sea.h"#include "srv0srv.h"#include "mem0dbg.c"#include <stdarg.h>Include dependency graph for mem0mem.c:

Go to the source code of this file.
Functions | |
| void * | mem_alloc_func_noninline (ulint n, const char *file_name, ulint line) |
| char * | mem_heap_strdup (mem_heap_t *heap, const char *str) |
| void * | mem_heap_dup (mem_heap_t *heap, const void *data, ulint len) |
| void * | mem_heap_cat (mem_heap_t *heap, const void *b1, ulint len1, const void *b2, ulint len2) |
| char * | mem_heap_strcat (mem_heap_t *heap, const char *s1, const char *s2) |
| static ulint | mem_heap_printf_low (char *buf, const char *format, va_list ap) |
| char * | mem_heap_printf (mem_heap_t *heap, const char *format,...) |
| mem_block_t * | mem_heap_create_block (mem_heap_t *heap, ulint n, void *init_block, ulint type, const char *file_name, ulint line) |
| mem_block_t * | mem_heap_add_block (mem_heap_t *heap, ulint n) |
| void | mem_heap_block_free (mem_heap_t *heap, mem_block_t *block) |
| void | mem_heap_free_block_free (mem_heap_t *heap) |
Definition at line 94 of file mem0mem.c.
References mem_alloc_func().
00096 : free storage */ 00097 ulint n, /* in: desired number of bytes */ 00098 const char* file_name, /* in: file name where created */ 00099 ulint line) /* in: line where created */ 00100 { 00101 return(mem_alloc_func(n, file_name, line)); 00102 }
Here is the call graph for this function:

| mem_block_t* mem_heap_add_block | ( | mem_heap_t * | heap, | |
| ulint | n | |||
| ) |
Definition at line 427 of file mem0mem.c.
References yaSSL::block, list(), MEM_BLOCK_STANDARD_SIZE, mem_heap_check(), mem_heap_create_block(), MEM_HEAP_DYNAMIC, MEM_MAX_ALLOC_IN_BUF, NULL, ut_a, ut_ad, UT_LIST_GET_LAST, and UT_LIST_INSERT_AFTER.
00429 : created block, NULL if did not 00430 succeed (only possible for 00431 MEM_HEAP_BTR_SEARCH type heaps)*/ 00432 mem_heap_t* heap, /* in: memory heap */ 00433 ulint n) /* in: number of bytes user needs */ 00434 { 00435 mem_block_t* block; 00436 mem_block_t* new_block; 00437 ulint new_size; 00438 00439 ut_ad(mem_heap_check(heap)); 00440 00441 block = UT_LIST_GET_LAST(heap->base); 00442 00443 /* We have to allocate a new block. The size is always at least 00444 doubled until the standard size is reached. After that the size 00445 stays the same, except in cases where the caller needs more space. */ 00446 00447 new_size = 2 * mem_block_get_len(block); 00448 00449 if (heap->type != MEM_HEAP_DYNAMIC) { 00450 /* From the buffer pool we allocate buffer frames */ 00451 ut_a(n <= MEM_MAX_ALLOC_IN_BUF); 00452 00453 if (new_size > MEM_MAX_ALLOC_IN_BUF) { 00454 new_size = MEM_MAX_ALLOC_IN_BUF; 00455 } 00456 } else if (new_size > MEM_BLOCK_STANDARD_SIZE) { 00457 00458 new_size = MEM_BLOCK_STANDARD_SIZE; 00459 } 00460 00461 if (new_size < n) { 00462 new_size = n; 00463 } 00464 00465 new_block = mem_heap_create_block(heap, new_size, NULL, heap->type, 00466 heap->file_name, heap->line); 00467 if (new_block == NULL) { 00468 00469 return(NULL); 00470 } 00471 00472 /* Add the new block as the last block */ 00473 00474 UT_LIST_INSERT_AFTER(list, heap->base, block, new_block); 00475 00476 return(new_block); 00477 }
Here is the call graph for this function:

| void mem_heap_block_free | ( | mem_heap_t * | heap, | |
| mem_block_t * | block | |||
| ) |
Definition at line 483 of file mem0mem.c.
References yaSSL::block, buf_frame_free(), init_block(), list(), mem_analyze_corruption(), mem_area_free(), MEM_BLOCK_MAGIC_N, mem_comm_pool, MEM_FREED_BLOCK_MAGIC_N, MEM_HEAP_BUFFER, MEM_HEAP_DYNAMIC, mem_pool_mutex_enter(), mem_pool_mutex_exit(), UNIV_PAGE_SIZE, ut_ad, and UT_LIST_REMOVE.
00485 : heap */ 00486 mem_block_t* block) /* in: block to free */ 00487 { 00488 ulint type; 00489 ulint len; 00490 ibool init_block; 00491 00492 if (block->magic_n != MEM_BLOCK_MAGIC_N) { 00493 mem_analyze_corruption(block); 00494 } 00495 00496 UT_LIST_REMOVE(list, heap->base, block); 00497 00498 #ifdef MEM_PERIODIC_CHECK 00499 mem_pool_mutex_enter(); 00500 00501 UT_LIST_REMOVE(mem_block_list, mem_block_list, block); 00502 00503 mem_pool_mutex_exit(); 00504 #endif 00505 type = heap->type; 00506 len = block->len; 00507 init_block = block->init_block; 00508 block->magic_n = MEM_FREED_BLOCK_MAGIC_N; 00509 00510 #ifdef UNIV_MEM_DEBUG 00511 /* In the debug version we set the memory to a random combination 00512 of hex 0xDE and 0xAD. */ 00513 00514 mem_erase_buf((byte*)block, len); 00515 00516 #endif 00517 00518 if (init_block) { 00519 /* Do not have to free: do nothing */ 00520 00521 } else if (type == MEM_HEAP_DYNAMIC) { 00522 00523 mem_area_free(block, mem_comm_pool); 00524 } else { 00525 ut_ad(type & MEM_HEAP_BUFFER); 00526 00527 if (len >= UNIV_PAGE_SIZE / 2) { 00528 buf_frame_free((byte*)block); 00529 } else { 00530 mem_area_free(block, mem_comm_pool); 00531 } 00532 } 00533 }
Here is the call graph for this function:

| void* mem_heap_cat | ( | mem_heap_t * | heap, | |
| const void * | b1, | |||
| ulint | len1, | |||
| const void * | b2, | |||
| ulint | len2 | |||
| ) |
Definition at line 135 of file mem0mem.c.
References mem_heap_alloc(), and memcpy.
00137 : the result */ 00138 mem_heap_t* heap, /* in: memory heap where result is allocated */ 00139 const void* b1, /* in: block 1 */ 00140 ulint len1, /* in: length of b1, in bytes */ 00141 const void* b2, /* in: block 2 */ 00142 ulint len2) /* in: length of b2, in bytes */ 00143 { 00144 void* res = mem_heap_alloc(heap, len1 + len2); 00145 00146 memcpy(res, b1, len1); 00147 memcpy((char*)res + len1, b2, len2); 00148 00149 return(res); 00150 }
Here is the call graph for this function:

| mem_block_t* mem_heap_create_block | ( | mem_heap_t * | heap, | |
| ulint | n, | |||
| void * | init_block, | |||
| ulint | type, | |||
| const char * | file_name, | |||
| ulint | line | |||
| ) |
Definition at line 325 of file mem0mem.c.
References yaSSL::block, buf_frame_alloc(), mem_analyze_corruption(), mem_area_alloc(), MEM_BLOCK_HEADER_SIZE, MEM_BLOCK_MAGIC_N, MEM_BLOCK_START_SIZE, mem_comm_pool, MEM_HEAP_BTR_SEARCH, MEM_HEAP_BUFFER, MEM_HEAP_DYNAMIC, MEM_MAX_ALLOC_IN_BUF, mem_pool_mutex_enter(), mem_pool_mutex_exit(), MEM_SPACE_NEEDED, NULL, TRUE, UNIV_PAGE_SIZE, ut_a, ut_ad, UT_LIST_ADD_LAST, UT_LIST_INIT, and ut_strlcpy_rev().
Referenced by mem_heap_add_block().
00327 : memory heap block, NULL if 00328 did not succeed (only possible for 00329 MEM_HEAP_BTR_SEARCH type heaps) */ 00330 mem_heap_t* heap, /* in: memory heap or NULL if first block 00331 should be created */ 00332 ulint n, /* in: number of bytes needed for user data, or 00333 if init_block is not NULL, its size in bytes */ 00334 void* init_block, /* in: init block in fast create, 00335 type must be MEM_HEAP_DYNAMIC */ 00336 ulint type, /* in: type of heap: MEM_HEAP_DYNAMIC or 00337 MEM_HEAP_BUFFER */ 00338 const char* file_name,/* in: file name where created */ 00339 ulint line) /* in: line where created */ 00340 { 00341 mem_block_t* block; 00342 ulint len; 00343 00344 ut_ad((type == MEM_HEAP_DYNAMIC) || (type == MEM_HEAP_BUFFER) 00345 || (type == MEM_HEAP_BUFFER + MEM_HEAP_BTR_SEARCH)); 00346 00347 if (heap && heap->magic_n != MEM_BLOCK_MAGIC_N) { 00348 mem_analyze_corruption(heap); 00349 } 00350 00351 /* In dynamic allocation, calculate the size: block header + data. */ 00352 00353 if (init_block != NULL) { 00354 ut_ad(type == MEM_HEAP_DYNAMIC); 00355 ut_ad(n > MEM_BLOCK_START_SIZE + MEM_BLOCK_HEADER_SIZE); 00356 len = n; 00357 block = init_block; 00358 00359 } else if (type == MEM_HEAP_DYNAMIC) { 00360 00361 len = MEM_BLOCK_HEADER_SIZE + MEM_SPACE_NEEDED(n); 00362 block = mem_area_alloc(len, mem_comm_pool); 00363 } else { 00364 ut_ad(n <= MEM_MAX_ALLOC_IN_BUF); 00365 00366 len = MEM_BLOCK_HEADER_SIZE + MEM_SPACE_NEEDED(n); 00367 00368 if (len < UNIV_PAGE_SIZE / 2) { 00369 00370 block = mem_area_alloc(len, mem_comm_pool); 00371 } else { 00372 len = UNIV_PAGE_SIZE; 00373 00374 if ((type & MEM_HEAP_BTR_SEARCH) && heap) { 00375 /* We cannot allocate the block from the 00376 buffer pool, but must get the free block from 00377 the heap header free block field */ 00378 00379 block = (mem_block_t*)heap->free_block; 00380 heap->free_block = NULL; 00381 } else { 00382 block = (mem_block_t*)buf_frame_alloc(); 00383 } 00384 } 00385 } 00386 00387 if (block == NULL) { 00388 /* Only MEM_HEAP_BTR_SEARCH allocation should ever fail. */ 00389 ut_a(type & MEM_HEAP_BTR_SEARCH); 00390 00391 return(NULL); 00392 } 00393 00394 block->magic_n = MEM_BLOCK_MAGIC_N; 00395 ut_strlcpy_rev(block->file_name, file_name, sizeof(block->file_name)); 00396 block->line = line; 00397 00398 #ifdef MEM_PERIODIC_CHECK 00399 mem_pool_mutex_enter(); 00400 00401 if (!mem_block_list_inited) { 00402 mem_block_list_inited = TRUE; 00403 UT_LIST_INIT(mem_block_list); 00404 } 00405 00406 UT_LIST_ADD_LAST(mem_block_list, mem_block_list, block); 00407 00408 mem_pool_mutex_exit(); 00409 #endif 00410 mem_block_set_len(block, len); 00411 mem_block_set_type(block, type); 00412 mem_block_set_free(block, MEM_BLOCK_HEADER_SIZE); 00413 mem_block_set_start(block, MEM_BLOCK_HEADER_SIZE); 00414 00415 block->free_block = NULL; 00416 block->init_block = (init_block != NULL); 00417 00418 ut_ad((ulint)MEM_BLOCK_HEADER_SIZE < len); 00419 00420 return(block); 00421 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void* mem_heap_dup | ( | mem_heap_t * | heap, | |
| const void * | data, | |||
| ulint | len | |||
| ) |
Definition at line 121 of file mem0mem.c.
References mem_heap_alloc(), and memcpy.
Referenced by mem_heap_strdup(), and pars_sql().
00123 : a copy of the data */ 00124 mem_heap_t* heap, /* in: memory heap where copy is allocated */ 00125 const void* data, /* in: data to be copied */ 00126 ulint len) /* in: length of data, in bytes */ 00127 { 00128 return(memcpy(mem_heap_alloc(heap, len), data, len)); 00129 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void mem_heap_free_block_free | ( | mem_heap_t * | heap | ) |
Definition at line 539 of file mem0mem.c.
References buf_frame_free(), and NULL.
00541 : heap */ 00542 { 00543 if (heap->free_block) { 00544 00545 buf_frame_free(heap->free_block); 00546 00547 heap->free_block = NULL; 00548 } 00549 }
Here is the call graph for this function:

| char* mem_heap_printf | ( | mem_heap_t * | heap, | |
| const char * | format, | |||
| ... | ||||
| ) |
Definition at line 295 of file mem0mem.c.
References mem_heap_alloc(), mem_heap_printf_low(), and NULL.
00297 : heap-allocated formatted string */ 00298 mem_heap_t* heap, /* in: memory heap */ 00299 const char* format, /* in: format string */ 00300 ...) 00301 { 00302 va_list ap; 00303 char* str; 00304 ulint len; 00305 00306 /* Calculate length of string */ 00307 len = 0; 00308 va_start(ap, format); 00309 len = mem_heap_printf_low(NULL, format, ap); 00310 va_end(ap); 00311 00312 /* Now create it for real. */ 00313 str = mem_heap_alloc(heap, len); 00314 va_start(ap, format); 00315 mem_heap_printf_low(str, format, ap); 00316 va_end(ap); 00317 00318 return(str); 00319 }
Here is the call graph for this function:

| static ulint mem_heap_printf_low | ( | char * | buf, | |
| const char * | format, | |||
| va_list | ap | |||
| ) | [static] |
Definition at line 182 of file mem0mem.c.
References FALSE, memcpy, strlen(), TRUE, ut_a, and ut_error.
Referenced by mem_heap_printf().
00184 : length of formatted string, 00185 including terminating NUL */ 00186 char* buf, /* in/out: buffer to store formatted string 00187 in, or NULL to just calculate length */ 00188 const char* format, /* in: format string */ 00189 va_list ap) /* in: arguments */ 00190 { 00191 ulint len = 0; 00192 00193 while (*format) { 00194 00195 /* Does this format specifier have the 'l' length modifier. */ 00196 ibool is_long = FALSE; 00197 00198 /* Length of one parameter. */ 00199 size_t plen; 00200 00201 if (*format++ != '%') { 00202 /* Non-format character. */ 00203 00204 len++; 00205 00206 if (buf) { 00207 *buf++ = *(format - 1); 00208 } 00209 00210 continue; 00211 } 00212 00213 if (*format == 'l') { 00214 is_long = TRUE; 00215 format++; 00216 } 00217 00218 switch (*format++) { 00219 case 's': 00220 /* string */ 00221 { 00222 char* s = va_arg(ap, char*); 00223 00224 /* "%ls" is a non-sensical format specifier. */ 00225 ut_a(!is_long); 00226 00227 plen = strlen(s); 00228 len += plen; 00229 00230 if (buf) { 00231 memcpy(buf, s, plen); 00232 buf += plen; 00233 } 00234 } 00235 00236 break; 00237 00238 case 'u': 00239 /* unsigned int */ 00240 { 00241 char tmp[32]; 00242 unsigned long val; 00243 00244 /* We only support 'long' values for now. */ 00245 ut_a(is_long); 00246 00247 val = va_arg(ap, unsigned long); 00248 00249 plen = sprintf(tmp, "%lu", val); 00250 len += plen; 00251 00252 if (buf) { 00253 memcpy(buf, tmp, plen); 00254 buf += plen; 00255 } 00256 } 00257 00258 break; 00259 00260 case '%': 00261 00262 /* "%l%" is a non-sensical format specifier. */ 00263 ut_a(!is_long); 00264 00265 len++; 00266 00267 if (buf) { 00268 *buf++ = '%'; 00269 } 00270 00271 break; 00272 00273 default: 00274 ut_error; 00275 } 00276 } 00277 00278 /* For the NUL character. */ 00279 len++; 00280 00281 if (buf) { 00282 *buf = '\0'; 00283 } 00284 00285 return(len); 00286 }
Here is the call graph for this function:

Here is the caller graph for this function:

| char* mem_heap_strcat | ( | mem_heap_t * | heap, | |
| const char * | s1, | |||
| const char * | s2 | |||
| ) |
Definition at line 156 of file mem0mem.c.
References mem_heap_alloc(), memcpy, and strlen().
Referenced by row_delete_constraint().
00158 : the result */ 00159 mem_heap_t* heap, /* in: memory heap where string is allocated */ 00160 const char* s1, /* in: string 1 */ 00161 const char* s2) /* in: string 2 */ 00162 { 00163 char* s; 00164 ulint s1_len = strlen(s1); 00165 ulint s2_len = strlen(s2); 00166 00167 s = mem_heap_alloc(heap, s1_len + s2_len + 1); 00168 00169 memcpy(s, s1, s1_len); 00170 memcpy(s + s1_len, s2, s2_len); 00171 00172 s[s1_len + s2_len] = '\0'; 00173 00174 return(s); 00175 }
Here is the call graph for this function:

Here is the caller graph for this function:

| char* mem_heap_strdup | ( | mem_heap_t * | heap, | |
| const char * | str | |||
| ) |
Definition at line 108 of file mem0mem.c.
References mem_heap_dup(), and strlen().
Referenced by dict_create_foreign_constraints_low(), dict_load_foreign(), dict_mem_index_create(), dict_mem_table_add_col(), dict_mem_table_create(), dict_table_rename_in_cache(), and sym_tab_add_bound_id().
00110 : a copy of the string */ 00111 mem_heap_t* heap, /* in: memory heap where string is allocated */ 00112 const char* str) /* in: string to be copied */ 00113 { 00114 return(mem_heap_dup(heap, str, strlen(str) + 1)); 00115 }
Here is the call graph for this function:

Here is the caller graph for this function:

1.4.7

