Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

sm_malloc_stats.c 1.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * This file is a part of SMalloc.
  3. * SMalloc is MIT licensed.
  4. * Copyright (c) 2017 Andrey Rys.
  5. */
  6. #include "smalloc_i.h"
  7. int sm_malloc_stats_pool(struct smalloc_pool *spool, size_t *total, size_t *user, size_t *free, int *nr_blocks)
  8. {
  9. struct smalloc_hdr *shdr, *basehdr;
  10. int r = 0;
  11. if (!smalloc_verify_pool(spool)) {
  12. errno = EINVAL;
  13. return -1;
  14. }
  15. if (!total && !user && !free && !nr_blocks) return 0;
  16. if (total) *total = 0;
  17. if (user) *user = 0;
  18. if (free) *free = 0;
  19. if (nr_blocks) *nr_blocks = 0;
  20. shdr = basehdr = spool->pool;
  21. while (CHAR_PTR(shdr)-CHAR_PTR(basehdr) < spool->pool_size) {
  22. if (smalloc_is_alloc(spool, shdr)) {
  23. if (total) *total += HEADER_SZ + shdr->rsz + HEADER_SZ;
  24. if (user) *user += shdr->usz;
  25. if (nr_blocks) *nr_blocks += 1;
  26. r = 1;
  27. }
  28. shdr++;
  29. }
  30. *free = spool->pool_size - *total;
  31. return r;
  32. }
  33. int sm_malloc_stats(size_t *total, size_t *user, size_t *free, int *nr_blocks)
  34. {
  35. return sm_malloc_stats_pool(&smalloc_curr_pool, total, user, free, nr_blocks);
  36. }