~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Brian Aker
  • Date: 2008-09-04 19:31:00 UTC
  • Revision ID: brian@tangent.org-20080904193100-l849hgghfy4urj43
Changing default character set from this point on.

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
allocations of small buffers. */
51
51
 
52
52
#define MEM_BLOCK_START_SIZE            64
53
 
#define MEM_BLOCK_STANDARD_SIZE         \
54
 
        (UNIV_PAGE_SIZE >= 16384 ? 8000 : MEM_MAX_ALLOC_IN_BUF)
 
53
#define MEM_BLOCK_STANDARD_SIZE         8000
55
54
 
56
55
/* If a memory heap is allowed to grow into the buffer pool, the following
57
56
is the maximum size for a single allocated buffer: */
59
58
 
60
59
/**********************************************************************
61
60
Initializes the memory system. */
62
 
UNIV_INTERN
 
61
 
63
62
void
64
63
mem_init(
65
64
/*=====*/
69
68
heap creation. */
70
69
 
71
70
#define mem_heap_create(N)      mem_heap_create_func(\
72
 
                (N), MEM_HEAP_DYNAMIC, __FILE__, __LINE__)
 
71
                (N), NULL, MEM_HEAP_DYNAMIC, __FILE__, __LINE__)
73
72
/******************************************************************
74
73
Use this macro instead of the corresponding function! Macro for memory
75
74
heap creation. */
76
75
 
77
76
#define mem_heap_create_in_buffer(N)    mem_heap_create_func(\
78
 
                (N), MEM_HEAP_BUFFER, __FILE__, __LINE__)
 
77
                (N), NULL, MEM_HEAP_BUFFER, __FILE__, __LINE__)
79
78
/******************************************************************
80
79
Use this macro instead of the corresponding function! Macro for memory
81
80
heap creation. */
82
81
 
83
82
#define mem_heap_create_in_btr_search(N)        mem_heap_create_func(\
84
 
                (N), MEM_HEAP_BTR_SEARCH | MEM_HEAP_BUFFER,\
 
83
                (N), NULL, MEM_HEAP_BTR_SEARCH | MEM_HEAP_BUFFER,\
85
84
                __FILE__, __LINE__)
 
85
/******************************************************************
 
86
Use this macro instead of the corresponding function! Macro for fast
 
87
memory heap creation. An initial block of memory B is given by the
 
88
caller, N is its size, and this memory block is not freed by
 
89
mem_heap_free. See the parameter comment in mem_heap_create_func below. */
 
90
 
 
91
#define mem_heap_fast_create(N, B)      mem_heap_create_func(\
 
92
                (N), (B), MEM_HEAP_DYNAMIC, __FILE__, __LINE__)
86
93
 
87
94
/******************************************************************
88
95
Use this macro instead of the corresponding function! Macro for memory
104
111
        ulint           n,              /* in: desired start block size,
105
112
                                        this means that a single user buffer
106
113
                                        of size n will fit in the block,
107
 
                                        0 creates a default size block */
 
114
                                        0 creates a default size block;
 
115
                                        if init_block is not NULL, n tells
 
116
                                        its size in bytes */
 
117
        void*           init_block,     /* in: if very fast creation is
 
118
                                        wanted, the caller can reserve some
 
119
                                        memory from its stack, for example,
 
120
                                        and pass it as the the initial block
 
121
                                        to the heap: then no OS call of malloc
 
122
                                        is needed at the creation. CAUTION:
 
123
                                        the caller must make sure the initial
 
124
                                        block is not unintentionally erased
 
125
                                        (if allocated in the stack), before
 
126
                                        the memory heap is explicitly freed. */
108
127
        ulint           type,           /* in: heap type */
109
128
        const char*     file_name,      /* in: file name where created */
110
129
        ulint           line);          /* in: line where created */
120
139
        const char*     file_name,      /* in: file name where freed */
121
140
        ulint           line);          /* in: line where freed */
122
141
/*******************************************************************
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
142
Allocates n bytes of memory from a memory heap. */
135
143
UNIV_INLINE
136
144
void*
198
206
Use this macro instead of the corresponding function!
199
207
Macro for memory buffer allocation */
200
208
 
201
 
#define mem_zalloc(N)   memset(mem_alloc(N), 0, (N));
 
209
#define mem_alloc(N)    mem_alloc_func((N), __FILE__, __LINE__)
 
210
/******************************************************************
 
211
Use this macro instead of the corresponding function!
 
212
Macro for memory buffer allocation */
202
213
 
203
 
#define mem_alloc(N)    mem_alloc_func((N), NULL, __FILE__, __LINE__)
204
 
#define mem_alloc2(N,S) mem_alloc_func((N), (S), __FILE__, __LINE__)
 
214
#define mem_alloc_noninline(N)    mem_alloc_func_noninline(\
 
215
                                          (N), __FILE__, __LINE__)
205
216
/*******************************************************************
206
217
NOTE: Use the corresponding macro instead of this function.
207
218
Allocates a single buffer of memory from the dynamic memory of
212
223
mem_alloc_func(
213
224
/*===========*/
214
225
                                        /* out, own: free storage */
215
 
        ulint           n,              /* in: requested size in bytes */
216
 
        ulint*          size,           /* out: allocated size in bytes,
217
 
                                        or NULL */
 
226
        ulint           n,              /* in: desired number of bytes */
218
227
        const char*     file_name,      /* in: file name where created */
219
 
        ulint           line);          /* in: line where created */
 
228
        ulint           line            /* in: line where created */
 
229
);
 
230
/*******************************************************************
 
231
NOTE: Use the corresponding macro instead of this function.
 
232
Allocates a single buffer of memory from the dynamic memory of
 
233
the C compiler. Is like malloc of C. The buffer must be freed
 
234
with mem_free. */
220
235
 
 
236
void*
 
237
mem_alloc_func_noninline(
 
238
/*=====================*/
 
239
                                        /* out, own: free storage */
 
240
        ulint           n,              /* in: desired number of bytes */
 
241
        const char*     file_name,      /* in: file name where created */
 
242
        ulint           line            /* in: line where created */
 
243
        );
221
244
/******************************************************************
222
245
Use this macro instead of the corresponding function!
223
246
Macro for memory buffer freeing */
258
281
 
259
282
/**************************************************************************
260
283
Duplicates a NUL-terminated string, allocated from a memory heap. */
261
 
UNIV_INTERN
 
284
 
262
285
char*
263
286
mem_heap_strdup(
264
287
/*============*/
279
302
 
280
303
/**************************************************************************
281
304
Concatenate two strings and return the result, using a memory heap. */
282
 
UNIV_INTERN
 
305
 
283
306
char*
284
307
mem_heap_strcat(
285
308
/*============*/
290
313
 
291
314
/**************************************************************************
292
315
Duplicate a block of data, allocated from a memory heap. */
293
 
UNIV_INTERN
 
316
 
294
317
void*
295
318
mem_heap_dup(
296
319
/*=========*/
301
324
 
302
325
/**************************************************************************
303
326
Concatenate two memory blocks and return the result, using a memory heap. */
304
 
UNIV_INTERN
 
327
 
305
328
void*
306
329
mem_heap_cat(
307
330
/*=========*/
317
340
formatted string from the given heap. This supports a very limited set of
318
341
the printf syntax: types 's' and 'u' and length modifier 'l' (which is
319
342
required for the 'u' type). */
320
 
UNIV_INTERN
 
343
 
321
344
char*
322
345
mem_heap_printf(
323
346
/*============*/
330
353
/**********************************************************************
331
354
Goes through the list of all allocated mem blocks, checks their magic
332
355
numbers, and reports possible corruption. */
333
 
UNIV_INTERN
 
356
 
334
357
void
335
358
mem_validate_all_blocks(void);
336
359
/*=========================*/
354
377
        ulint   len;    /* physical length of this block in bytes */
355
378
        ulint   type;   /* type of heap: MEM_HEAP_DYNAMIC, or
356
379
                        MEM_HEAP_BUF possibly ORed to MEM_HEAP_BTR_SEARCH */
 
380
        ibool   init_block; /* TRUE if this is the first block used in fast
 
381
                        creation of a heap: the memory will be freed
 
382
                        by the creator, not by mem_heap_free */
357
383
        ulint   free;   /* offset in bytes of the first free position for
358
384
                        user data in the block */
359
385
        ulint   start;  /* the value of the struct field 'free' at the
360
386
                        creation of the block */
361
 
        void*   free_block;
 
387
        byte*   free_block;
362
388
                        /* if the MEM_HEAP_BTR_SEARCH bit is set in type,
363
389
                        and this is the heap root, this can contain an
364
390
                        allocated buffer frame, which can be appended as a
365
391
                        free block to the heap, if we need more space;
366
392
                        otherwise, this is NULL */
367
 
        void*   buf_block;
368
 
                        /* if this block has been allocated from the buffer
369
 
                        pool, this contains the buf_block_t handle;
370
 
                        otherwise, this is NULL */
371
393
#ifdef MEM_PERIODIC_CHECK
372
394
        UT_LIST_NODE_T(mem_block_t) mem_block_list;
373
395
                        /* List of all mem blocks allocated; protected