Clone of PhatAC @ https://github.com/floaterxk/PhatAC

my_alloc.h 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 as published by
  4. the Free Software Foundation; version 2 of the License.
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License
  10. along with this program; if not, write to the Free Software
  11. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
  12. /*
  13. Data structures for mysys/my_alloc.c (root memory allocator)
  14. */
  15. #ifndef _my_alloc_h
  16. #define _my_alloc_h
  17. #define ALLOC_MAX_BLOCK_TO_DROP 4096
  18. #define ALLOC_MAX_BLOCK_USAGE_BEFORE_DROP 10
  19. /* PSI_memory_key */
  20. #include "mysql/psi/psi_memory.h"
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. typedef struct st_used_mem
  25. { /* struct for once_alloc (block) */
  26. struct st_used_mem *next; /* Next block in use */
  27. unsigned int left; /* memory left in block */
  28. unsigned int size; /* size of block */
  29. } USED_MEM;
  30. typedef struct st_mem_root
  31. {
  32. USED_MEM *free; /* blocks with free memory in it */
  33. USED_MEM *used; /* blocks almost without free memory */
  34. USED_MEM *pre_alloc; /* preallocated block */
  35. /* if block have less memory it will be put in 'used' list */
  36. size_t min_malloc;
  37. size_t block_size; /* initial block size */
  38. unsigned int block_num; /* allocated blocks counter */
  39. /*
  40. first free block in queue test counter (if it exceed
  41. MAX_BLOCK_USAGE_BEFORE_DROP block will be dropped in 'used' list)
  42. */
  43. unsigned int first_block_usage;
  44. /*
  45. Maximum amount of memory this mem_root can hold. A value of 0
  46. implies there is no limit.
  47. */
  48. size_t max_capacity;
  49. /* Allocated size for this mem_root */
  50. size_t allocated_size;
  51. /* Enable this for error reporting if capacity is exceeded */
  52. my_bool error_for_capacity_exceeded;
  53. void (*error_handler)(void);
  54. PSI_memory_key m_psi_key;
  55. } MEM_ROOT;
  56. #ifdef __cplusplus
  57. }
  58. #endif
  59. #endif