THIS IS A TEST INSTANCE ONLY! REPOSITORIES CAN BE DELETED AT ANY TIME!

Git Source Code Mirror - This is a publish-only repository and all pull requests are ignored. Please follow Documentation/SubmittingPatches procedure for any of your improvements.
git
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

58 lignes
1.4KB

  1. #ifndef MEM_POOL_H
  2. #define MEM_POOL_H
  3. struct mp_block {
  4. struct mp_block *next_block;
  5. char *next_free;
  6. char *end;
  7. uintmax_t space[FLEX_ARRAY]; /* more */
  8. };
  9. struct mem_pool {
  10. struct mp_block *mp_block;
  11. /*
  12. * The amount of available memory to grow the pool by.
  13. * This size does not include the overhead for the mp_block.
  14. */
  15. size_t block_alloc;
  16. /* The total amount of memory allocated by the pool. */
  17. size_t pool_alloc;
  18. };
  19. /*
  20. * Initialize mem_pool with specified initial size.
  21. */
  22. void mem_pool_init(struct mem_pool **mem_pool, size_t initial_size);
  23. /*
  24. * Discard a memory pool and free all the memory it is responsible for.
  25. */
  26. void mem_pool_discard(struct mem_pool *mem_pool, int invalidate_memory);
  27. /*
  28. * Alloc memory from the mem_pool.
  29. */
  30. void *mem_pool_alloc(struct mem_pool *pool, size_t len);
  31. /*
  32. * Allocate and zero memory from the memory pool.
  33. */
  34. void *mem_pool_calloc(struct mem_pool *pool, size_t count, size_t size);
  35. /*
  36. * Move the memory associated with the 'src' pool to the 'dst' pool. The 'src'
  37. * pool will be empty and not contain any memory. It still needs to be free'd
  38. * with a call to `mem_pool_discard`.
  39. */
  40. void mem_pool_combine(struct mem_pool *dst, struct mem_pool *src);
  41. /*
  42. * Check if a memory pointed at by 'mem' is part of the range of
  43. * memory managed by the specified mem_pool.
  44. */
  45. int mem_pool_contains(struct mem_pool *mem_pool, void *mem);
  46. #endif