1 /***************************************************************************** 2 3 Copyright (c) 1994, 2009, Oracle and/or its affiliates. All Rights Reserved. 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License, version 2.0, 7 as published by the Free Software Foundation. 8 9 This program is also distributed with certain software (including 10 but not limited to OpenSSL) that is licensed under separate terms, 11 as designated in a particular file or component or in included license 12 documentation. The authors of MySQL hereby grant you an additional 13 permission to link the program and your derivative works with the 14 separately licensed software that they have included with MySQL. 15 16 This program is distributed in the hope that it will be useful, 17 but WITHOUT ANY WARRANTY; without even the implied warranty of 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 GNU General Public License, version 2.0, for more details. 20 21 You should have received a copy of the GNU General Public License along with 22 this program; if not, write to the Free Software Foundation, Inc., 23 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA 24 25 *****************************************************************************/ 26 27 /**************************************************//** 28 @file include/mem0pool.h 29 The lowest-level memory management 30 31 Created 6/9/1994 Heikki Tuuri 32 *******************************************************/ 33 34 #ifndef mem0pool_h 35 #define mem0pool_h 36 37 #include "univ.i" 38 #include "os0file.h" 39 #include "ut0lst.h" 40 41 /** Memory pool */ 42 struct mem_pool_t; 43 44 /** The common memory pool */ 45 extern mem_pool_t* mem_comm_pool; 46 47 /** Memory area header */ 48 struct mem_area_t{ 49 ulint size_and_free; /*!< memory area size is obtained by 50 anding with ~MEM_AREA_FREE; area in 51 a free list if ANDing with 52 MEM_AREA_FREE results in nonzero */ 53 UT_LIST_NODE_T(mem_area_t) 54 free_list; /*!< free list node */ 55 }; 56 57 /** Each memory area takes this many extra bytes for control information */ 58 #define MEM_AREA_EXTRA_SIZE (ut_calc_align(sizeof(struct mem_area_t),\ 59 UNIV_MEM_ALIGNMENT)) 60 61 /********************************************************************//** 62 Creates a memory pool. 63 @return memory pool */ 64 UNIV_INTERN 65 mem_pool_t* 66 mem_pool_create( 67 /*============*/ 68 ulint size); /*!< in: pool size in bytes */ 69 /********************************************************************//** 70 Frees a memory pool. */ 71 UNIV_INTERN 72 void 73 mem_pool_free( 74 /*==========*/ 75 mem_pool_t* pool); /*!< in, own: memory pool */ 76 /********************************************************************//** 77 Allocates memory from a pool. NOTE: This low-level function should only be 78 used in mem0mem.*! 79 @return own: allocated memory buffer */ 80 UNIV_INTERN 81 void* 82 mem_area_alloc( 83 /*===========*/ 84 ulint* psize, /*!< in: requested size in bytes; for optimum 85 space usage, the size should be a power of 2 86 minus MEM_AREA_EXTRA_SIZE; 87 out: allocated size in bytes (greater than 88 or equal to the requested size) */ 89 mem_pool_t* pool); /*!< in: memory pool */ 90 /********************************************************************//** 91 Frees memory to a pool. */ 92 UNIV_INTERN 93 void 94 mem_area_free( 95 /*==========*/ 96 void* ptr, /*!< in, own: pointer to allocated memory 97 buffer */ 98 mem_pool_t* pool); /*!< in: memory pool */ 99 /********************************************************************//** 100 Returns the amount of reserved memory. 101 @return reserved mmeory in bytes */ 102 UNIV_INTERN 103 ulint 104 mem_pool_get_reserved( 105 /*==================*/ 106 mem_pool_t* pool); /*!< in: memory pool */ 107 /********************************************************************//** 108 Validates a memory pool. 109 @return TRUE if ok */ 110 UNIV_INTERN 111 ibool 112 mem_pool_validate( 113 /*==============*/ 114 mem_pool_t* pool); /*!< in: memory pool */ 115 /********************************************************************//** 116 Prints info of a memory pool. */ 117 UNIV_INTERN 118 void 119 mem_pool_print_info( 120 /*================*/ 121 FILE* outfile,/*!< in: output file to write to */ 122 mem_pool_t* pool); /*!< in: memory pool */ 123 124 125 #ifndef UNIV_NONINL 126 #include "mem0pool.ic" 127 #endif 128 129 #endif 130