1 // Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. 2 // 3 // This program is free software; you can redistribute it and/or modify 4 // it under the terms of the GNU General Public License, version 2.0, as 5 // published by the Free Software Foundation. 6 // 7 // This program is also distributed with certain software (including 8 // but not limited to OpenSSL) that is licensed under separate terms, 9 // as designated in a particular file or component or in included license 10 // documentation. The authors of MySQL hereby grant you an 11 // additional permission to link the program and your derivative works 12 // with the separately licensed software that they have included with 13 // MySQL. 14 // 15 // Without limiting anything contained in the foregoing, this file, 16 // which is part of MySQL Server, is also subject to the 17 // Universal FOSS Exception, version 1.0, a copy of which can be found at 18 // http://oss.oracle.com/licenses/universal-foss-exception. 19 // 20 // This program is distributed in the hope that it will be useful, but 21 // WITHOUT ANY WARRANTY; without even the implied warranty of 22 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 23 // See the GNU General Public License, version 2.0, for more details. 24 // 25 // You should have received a copy of the GNU General Public License 26 // along with this program; if not, write to the Free Software Foundation, Inc., 27 // 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 28 29 /* 30 Data structures for mysys/my_alloc.c (root memory allocator) 31 */ 32 33 #ifndef _my_alloc_h 34 #define _my_alloc_h 35 36 #define ALLOC_MAX_BLOCK_TO_DROP 4096 37 #define ALLOC_MAX_BLOCK_USAGE_BEFORE_DROP 10 38 39 /* PSI_memory_key */ 40 #include "mysql/psi/psi_memory.h" 41 42 #ifdef __cplusplus 43 extern "C" { 44 #endif 45 46 typedef struct st_used_mem 47 { /* struct for once_alloc (block) */ 48 struct st_used_mem *next; /* Next block in use */ 49 unsigned int left; /* memory left in block */ 50 unsigned int size; /* size of block */ 51 } USED_MEM; 52 53 54 typedef struct st_mem_root 55 { 56 USED_MEM *free; /* blocks with free memory in it */ 57 USED_MEM *used; /* blocks almost without free memory */ 58 USED_MEM *pre_alloc; /* preallocated block */ 59 /* if block have less memory it will be put in 'used' list */ 60 size_t min_malloc; 61 size_t block_size; /* initial block size */ 62 unsigned int block_num; /* allocated blocks counter */ 63 /* 64 first free block in queue test counter (if it exceed 65 MAX_BLOCK_USAGE_BEFORE_DROP block will be dropped in 'used' list) 66 */ 67 unsigned int first_block_usage; 68 69 /* 70 Maximum amount of memory this mem_root can hold. A value of 0 71 implies there is no limit. 72 */ 73 size_t max_capacity; 74 75 /* Allocated size for this mem_root */ 76 77 size_t allocated_size; 78 79 /* Enable this for error reporting if capacity is exceeded */ 80 my_bool error_for_capacity_exceeded; 81 82 void (*error_handler)(void); 83 84 PSI_memory_key m_psi_key; 85 } MEM_ROOT; 86 87 #ifdef __cplusplus 88 } 89 #endif 90 91 #endif 92