memory_pool_static_malloc.h 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*************************************************************************/
  2. /* memory_pool_static_malloc.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #ifndef MEMORY_POOL_STATIC_MALLOC_H
  30. #define MEMORY_POOL_STATIC_MALLOC_H
  31. #include "os/memory_pool_static.h"
  32. #include "os/mutex.h"
  33. /**
  34. @author Juan Linietsky <red@lunatea>
  35. */
  36. class MemoryPoolStaticMalloc : public MemoryPoolStatic {
  37. struct RingPtr {
  38. size_t size;
  39. const char *descr; /* description of memory */
  40. RingPtr *next;
  41. RingPtr *prev;
  42. };
  43. RingPtr *ringlist;
  44. size_t total_mem;
  45. int total_pointers;
  46. size_t max_mem;
  47. int max_pointers;
  48. Mutex *mutex;
  49. void* _alloc(size_t p_bytes,const char *p_description=""); ///< Pointer in p_description shold be to a const char const like "hello"
  50. void* _realloc(void *p_memory,size_t p_bytes); ///< Pointer in
  51. void _free(void *p_ptr); ///< Pointer in p_description shold be to a const char const
  52. public:
  53. virtual void* alloc(size_t p_bytes,const char *p_description=""); ///< Pointer in p_description shold be to a const char const like "hello"
  54. virtual void free(void *p_ptr); ///< Pointer in p_description shold be to a const char const
  55. virtual void* realloc(void *p_memory,size_t p_bytes); ///< Pointer in
  56. virtual size_t get_available_mem() const;
  57. virtual size_t get_total_usage();
  58. virtual size_t get_max_usage();
  59. /* Most likely available only if memory debugger was compiled in */
  60. virtual int get_alloc_count();
  61. virtual void * get_alloc_ptr(int p_alloc_idx);
  62. virtual const char* get_alloc_description(int p_alloc_idx);
  63. virtual size_t get_alloc_size(int p_alloc_idx);
  64. void dump_mem_to_file(const char* p_file);
  65. MemoryPoolStaticMalloc();
  66. ~MemoryPoolStaticMalloc();
  67. };
  68. #endif