my_alloc.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. void (*error_handler)(void);
  45. PSI_memory_key m_psi_key;
  46. } MEM_ROOT;
  47. #ifdef __cplusplus
  48. }
  49. #endif
  50. #endif