sdallocx.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "test/jemalloc_test.h"
  2. #define MAXALIGN (((size_t)1) << 25)
  3. #define NITER 4
  4. TEST_BEGIN(test_basic)
  5. {
  6. void *ptr = mallocx(64, 0);
  7. sdallocx(ptr, 64, 0);
  8. }
  9. TEST_END
  10. TEST_BEGIN(test_alignment_and_size)
  11. {
  12. size_t nsz, sz, alignment, total;
  13. unsigned i;
  14. void *ps[NITER];
  15. for (i = 0; i < NITER; i++)
  16. ps[i] = NULL;
  17. for (alignment = 8;
  18. alignment <= MAXALIGN;
  19. alignment <<= 1) {
  20. total = 0;
  21. for (sz = 1;
  22. sz < 3 * alignment && sz < (1U << 31);
  23. sz += (alignment >> (LG_SIZEOF_PTR-1)) - 1) {
  24. for (i = 0; i < NITER; i++) {
  25. nsz = nallocx(sz, MALLOCX_ALIGN(alignment) |
  26. MALLOCX_ZERO);
  27. ps[i] = mallocx(sz, MALLOCX_ALIGN(alignment) |
  28. MALLOCX_ZERO);
  29. total += nsz;
  30. if (total >= (MAXALIGN << 1))
  31. break;
  32. }
  33. for (i = 0; i < NITER; i++) {
  34. if (ps[i] != NULL) {
  35. sdallocx(ps[i], sz,
  36. MALLOCX_ALIGN(alignment));
  37. ps[i] = NULL;
  38. }
  39. }
  40. }
  41. }
  42. }
  43. TEST_END
  44. int
  45. main(void)
  46. {
  47. return (test(
  48. test_basic,
  49. test_alignment_and_size));
  50. }