21
21
MEM_HEAP_BTR_SEARCH type heaps) */
22
22
mem_heap_t* heap, /* in: memory heap or NULL if first block
23
23
should be created */
24
ulint n, /* in: number of bytes needed for user data */
24
ulint n, /* in: number of bytes needed for user data, or
25
if init_block is not NULL, its size in bytes */
26
void* init_block, /* in: init block in fast create,
27
type must be MEM_HEAP_DYNAMIC */
25
28
ulint type, /* in: type of heap: MEM_HEAP_DYNAMIC or
27
30
const char* file_name,/* in: file name where created */
28
31
ulint line); /* in: line where created */
29
32
/**********************************************************************
30
33
Frees a block from a memory heap. */
33
36
mem_heap_block_free(
34
37
/*================*/
36
39
mem_block_t* block); /* in: block to free */
37
40
/**********************************************************************
38
41
Frees the free_block field from a memory heap. */
41
44
mem_heap_free_block_free(
42
45
/*=====================*/
43
46
mem_heap_t* heap); /* in: heap */
44
47
/*******************************************************************
45
48
Adds a new block to a memory heap. */
48
51
mem_heap_add_block(
49
52
/*===============*/
122
125
/*******************************************************************
123
Allocates and zero-fills n bytes of memory from a memory heap. */
128
/* out: allocated, zero-filled storage */
129
mem_heap_t* heap, /* in: memory heap */
130
ulint n) /* in: number of bytes; if the heap is allowed
131
to grow into the buffer pool, this must be
132
<= MEM_MAX_ALLOC_IN_BUF */
135
ut_ad(!(heap->type & MEM_HEAP_BTR_SEARCH));
136
return(memset(mem_heap_alloc(heap, n), 0, n));
139
/*******************************************************************
140
126
Allocates n bytes of memory from a memory heap. */
412
398
ulint n, /* in: desired start block size,
413
399
this means that a single user buffer
414
400
of size n will fit in the block,
415
0 creates a default size block */
401
0 creates a default size block;
402
if init_block is not NULL, n tells
404
void* init_block, /* in: if very fast creation is
405
wanted, the caller can reserve some
406
memory from its stack, for example,
407
and pass it as the the initial block
408
to the heap: then no OS call of malloc
409
is needed at the creation. CAUTION:
410
the caller must make sure the initial
411
block is not unintentionally erased
412
(if allocated in the stack), before
413
the memory heap is explicitly freed. */
416
414
ulint type, /* in: heap type */
417
415
const char* file_name, /* in: file name where created */
418
416
ulint line) /* in: line where created */
420
418
mem_block_t* block;
423
n = MEM_BLOCK_START_SIZE;
421
block = mem_heap_create_block(NULL, n, init_block, type,
424
block = mem_heap_create_block(NULL, MEM_BLOCK_START_SIZE,
426
block = mem_heap_create_block(NULL, n, type, file_name, line);
428
429
if (block == NULL) {
501
502
/* out, own: free storage */
502
503
ulint n, /* in: desired number of bytes */
503
ulint* size, /* out: allocated size in bytes,
505
504
const char* file_name, /* in: file name where created */
506
ulint line) /* in: line where created */
505
ulint line /* in: line where created */
508
508
mem_heap_t* heap;
511
heap = mem_heap_create_func(n, MEM_HEAP_DYNAMIC, file_name, line);
511
heap = mem_heap_create_func(n, NULL, MEM_HEAP_DYNAMIC, file_name,
513
514
/* Note that as we created the first block in the heap big enough
514
515
for the buffer requested by the caller, the buffer will be in the
515
516
first block and thus we can calculate the pointer to the heap from
516
517
the pointer to the buffer when we free the memory buffer. */
518
if (UNIV_LIKELY_NULL(size)) {
519
/* Adjust the allocation to the actual size of the
521
ulint m = mem_block_get_len(heap)
522
- mem_block_get_free(heap);
523
#ifdef UNIV_MEM_DEBUG
524
m -= MEM_FIELD_HEADER_SIZE + MEM_FIELD_TRAILER_SIZE;
525
#endif /* UNIV_MEM_DEBUG */
530
519
buf = mem_heap_alloc(heap, n);
532
521
ut_a((byte*)heap == (byte*)buf - MEM_BLOCK_HEADER_SIZE
593
582
const char* str) /* in: string to be copied */
595
584
ulint len = strlen(str) + 1;
596
return((char*) memcpy(mem_alloc(len), str, len));
585
return(memcpy(mem_alloc(len), str, len));
599
588
/**************************************************************************
607
596
const char* str, /* in: string to be copied */
608
597
ulint len) /* in: length of str, in bytes */
610
char* s = (char*) mem_alloc(len + 1);
599
char* s = mem_alloc(len + 1);
612
return((char*) memcpy(s, str, len));
601
return(memcpy(s, str, len));
615
604
/**************************************************************************
624
613
const char* str, /* in: string to be copied */
625
614
ulint len) /* in: length of str, in bytes */
627
char* s = (char*) mem_heap_alloc(heap, len + 1);
616
char* s = mem_heap_alloc(heap, len + 1);
629
return((char*) memcpy(s, str, len));
618
return(memcpy(s, str, len));