Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tlsf.h 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #ifndef INCLUDED_tlsf
  2. #define INCLUDED_tlsf
  3. /*
  4. ** Two Level Segregated Fit memory allocator, version 3.0.
  5. ** Written by Matthew Conte, and placed in the Public Domain.
  6. ** http://tlsf.baisoku.org
  7. **
  8. ** Based on the original documentation by Miguel Masmano:
  9. ** http://rtportal.upv.es/rtmalloc/allocators/tlsf/index.shtml
  10. **
  11. ** Please see the accompanying Readme.txt for implementation
  12. ** notes and caveats.
  13. **
  14. ** This implementation was written to the specification
  15. ** of the document, therefore no GPL restrictions apply.
  16. */
  17. #include <stddef.h>
  18. #if defined(__cplusplus)
  19. extern "C" {
  20. #endif
  21. /* tlsf_t: a TLSF structure. Can contain 1 to N pools. */
  22. /* pool_t: a block of memory that TLSF can manage. */
  23. typedef void* tlsf_t;
  24. typedef void* pool_t;
  25. /* Create/destroy a memory pool. */
  26. tlsf_t tlsf_create(void* mem);
  27. tlsf_t tlsf_create_with_pool(void* mem, size_t bytes);
  28. void tlsf_destroy(tlsf_t tlsf);
  29. pool_t tlsf_get_pool(tlsf_t tlsf);
  30. /* Add/remove memory pools. */
  31. pool_t tlsf_add_pool(tlsf_t tlsf, void* mem, size_t bytes);
  32. void tlsf_remove_pool(tlsf_t tlsf, pool_t pool);
  33. /* malloc/memalign/realloc/free replacements. */
  34. void* tlsf_malloc(tlsf_t tlsf, size_t bytes);
  35. void* tlsf_memalign(tlsf_t tlsf, size_t align, size_t bytes);
  36. void* tlsf_realloc(tlsf_t tlsf, void* ptr, size_t size);
  37. void tlsf_free(tlsf_t tlsf, void* ptr);
  38. /* Returns internal block size, not original request size */
  39. size_t tlsf_block_size(void* ptr);
  40. /* Overheads/limits of internal structures. */
  41. size_t tlsf_size();
  42. size_t tlsf_align_size();
  43. size_t tlsf_block_size_min();
  44. size_t tlsf_block_size_max();
  45. size_t tlsf_pool_overhead();
  46. size_t tlsf_alloc_overhead();
  47. /* Debugging. */
  48. typedef void (*tlsf_walker)(void* ptr, size_t size, int used, void* user);
  49. void tlsf_walk_pool(pool_t pool, tlsf_walker walker, void* user);
  50. /* Returns nonzero if any internal consistency check fails. */
  51. int tlsf_check(tlsf_t tlsf);
  52. int tlsf_check_pool(pool_t pool);
  53. /* TODO add utilities for
  54. * - Find Unused Pool Chunks
  55. * - Define if the pool is running low
  56. */
  57. #if defined(__cplusplus)
  58. };
  59. #endif
  60. #endif