/src/memory/tlsf/tlsf.h

https://bitbucket.org/vivkin/gam3b00bs/ · C Header · 69 lines · 23 code · 13 blank · 33 comment · 0 complexity · 0215ea5ec3dfb216ccc320847fc04a5c MD5 · raw file

  1. #ifndef INCLUDED_tlsf
  2. #define INCLUDED_tlsf
  3. /// @addtogroup MemorySubsystem
  4. /// @{
  5. /*
  6. ** Two Level Segregated Fit memory allocator, version 1.9.
  7. ** Written by Matthew Conte, and placed in the Public Domain.
  8. ** http://tlsf.baisoku.org
  9. **
  10. ** Based on the original documentation by Miguel Masmano:
  11. ** http://rtportal.upv.es/rtmalloc/allocators/tlsf/index.shtml
  12. **
  13. ** Please see the accompanying Readme.txt for implementation
  14. ** notes and caveats.
  15. **
  16. ** This implementation was written to the specification
  17. ** of the document, therefore no GPL restrictions apply.
  18. */
  19. #include <stddef.h>
  20. #if defined(__cplusplus)
  21. extern "C" {
  22. #endif
  23. /* Create/destroy a memory pool. */
  24. /// Type of TLSF pool
  25. typedef void* tlsf_pool;
  26. /// Create TLSF pool on chunk of memory
  27. tlsf_pool tlsf_create(void* mem, size_t bytes);
  28. /// Destroy TLSF pool
  29. /// @note You should destroy underlying block yourself.
  30. void tlsf_destroy(tlsf_pool pool);
  31. /* malloc/memalign/realloc/free replacements. */
  32. /// Allocate block
  33. void* tlsf_malloc(tlsf_pool pool, size_t bytes);
  34. /// Allocate aligned block
  35. void* tlsf_memalign(tlsf_pool pool, size_t align, size_t bytes);
  36. /// Realloc block
  37. void* tlsf_realloc(tlsf_pool pool, void* ptr, size_t size);
  38. /// Free block
  39. void tlsf_free(tlsf_pool pool, void* ptr);
  40. /* Debugging. */
  41. typedef void (*tlsf_walker)(void* ptr, size_t size, int used, void* user);
  42. /// Heap walker
  43. void tlsf_walk_heap(tlsf_pool pool, tlsf_walker walker, void* user);
  44. /// Returns nonzero if heap check fails.
  45. int tlsf_check_heap(tlsf_pool pool);
  46. /// Returns internal block size, not original request size
  47. size_t tlsf_block_size(void* ptr);
  48. /// Overhead of per-pool internal structures.
  49. size_t tlsf_overhead();
  50. /// Get total size and free size
  51. void tlsf_statistics(tlsf_pool tlsf, size_t* total_size, size_t* free_size);
  52. #if defined(__cplusplus)
  53. };
  54. #endif
  55. /// @?
  56. #endif