my_alloc.h 2.9 KB

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