~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/include/mem0mem.ic

  • Committer: Monty Taylor
  • Date: 2008-09-15 17:24:04 UTC
  • Revision ID: monty@inaugust.com-20080915172404-ygh6hiyu0q7qpa9x
Removed strndup calls.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
 
13
13
/*******************************************************************
14
14
Creates a memory heap block where data can be allocated. */
15
 
UNIV_INTERN
 
15
 
16
16
mem_block_t*
17
17
mem_heap_create_block(
18
18
/*==================*/
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
26
29
                                MEM_HEAP_BUFFER */
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. */
31
 
UNIV_INTERN
 
34
 
32
35
void
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. */
39
 
UNIV_INTERN
 
42
 
40
43
void
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. */
46
 
UNIV_INTERN
 
49
 
47
50
mem_block_t*
48
51
mem_heap_add_block(
49
52
/*===============*/
120
123
}
121
124
 
122
125
/*******************************************************************
123
 
Allocates and zero-fills n bytes of memory from a memory heap. */
124
 
UNIV_INLINE
125
 
void*
126
 
mem_heap_zalloc(
127
 
/*============*/
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 */
133
 
{
134
 
        ut_ad(heap);
135
 
        ut_ad(!(heap->type & MEM_HEAP_BTR_SEARCH));
136
 
        return(memset(mem_heap_alloc(heap, n), 0, n));
137
 
}
138
 
 
139
 
/*******************************************************************
140
126
Allocates n bytes of memory from a memory heap. */
141
127
UNIV_INLINE
142
128
void*
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
 
403
                                        its size in bytes */
 
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 */
419
417
{
420
418
        mem_block_t*   block;
421
419
 
422
 
        if (!n) {
423
 
                n = MEM_BLOCK_START_SIZE;
 
420
        if (n > 0) {
 
421
                block = mem_heap_create_block(NULL, n, init_block, type,
 
422
                                              file_name, line);
 
423
        } else {
 
424
                block = mem_heap_create_block(NULL, MEM_BLOCK_START_SIZE,
 
425
                                              init_block, type,
 
426
                                              file_name, line);
424
427
        }
425
428
 
426
 
        block = mem_heap_create_block(NULL, n, type, file_name, line);
427
 
 
428
429
        if (block == NULL) {
429
430
 
430
431
                return(NULL);
500
501
/*===========*/
501
502
                                        /* out, own: free storage */
502
503
        ulint           n,              /* in: desired number of bytes */
503
 
        ulint*          size,           /* out: allocated size in bytes,
504
 
                                        or NULL */
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 */
 
506
        )
507
507
{
508
508
        mem_heap_t*     heap;
509
509
        void*           buf;
510
510
 
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,
 
512
                                    line);
512
513
 
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. */
517
518
 
518
 
        if (UNIV_LIKELY_NULL(size)) {
519
 
                /* Adjust the allocation to the actual size of the
520
 
                memory block. */
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 */
526
 
                ut_ad(m >= n);
527
 
                *size = n = m;
528
 
        }
529
 
 
530
519
        buf = mem_heap_alloc(heap, n);
531
520
 
532
521
        ut_a((byte*)heap == (byte*)buf - MEM_BLOCK_HEADER_SIZE
593
582
        const char*     str)    /* in: string to be copied */
594
583
{
595
584
        ulint   len = strlen(str) + 1;
596
 
        return((char*) memcpy(mem_alloc(len), str, len));
 
585
        return(memcpy(mem_alloc(len), str, len));
597
586
}
598
587
 
599
588
/**************************************************************************
607
596
        const char*     str,    /* in: string to be copied */
608
597
        ulint           len)    /* in: length of str, in bytes */
609
598
{
610
 
        char*   s = (char*) mem_alloc(len + 1);
 
599
        char*   s = mem_alloc(len + 1);
611
600
        s[len] = 0;
612
 
        return((char*) memcpy(s, str, len));
 
601
        return(memcpy(s, str, len));
613
602
}
614
603
 
615
604
/**************************************************************************
624
613
        const char*     str,    /* in: string to be copied */
625
614
        ulint           len)    /* in: length of str, in bytes */
626
615
{
627
 
        char*   s = (char*) mem_heap_alloc(heap, len + 1);
 
616
        char*   s = mem_heap_alloc(heap, len + 1);
628
617
        s[len] = 0;
629
 
        return((char*) memcpy(s, str, len));
 
618
        return(memcpy(s, str, len));
630
619
}