tfragment_alloc.nim 796 B

123456789101112131415161718192021222324252627282930313233343536
  1. discard """
  2. output: '''occupied ok: true
  3. total ok: true'''
  4. disabled: "true"
  5. """
  6. import strutils, data
  7. proc main =
  8. var m = 0
  9. for i in 0..1000_000:
  10. let size = sizes[i mod sizes.len]
  11. let p = alloc(size)
  12. if p == nil:
  13. quit "could not serve request!"
  14. dealloc p
  15. # c_fprintf(stdout, "iteration: %ld size: %ld\n", i, size)
  16. when defined(cpu64):
  17. # see https://github.com/nim-lang/Nim/issues/8509
  18. # this often made appveyor (on windows) fail with out of memory
  19. when defined(posix):
  20. # bug #7120
  21. var x = alloc(((1 shl 29) - 4) * 8)
  22. dealloc x
  23. main()
  24. let occ = getOccupiedMem()
  25. let total = getTotalMem()
  26. # Current values on Win64: 824KiB / 106.191MiB
  27. echo "occupied ok: ", occ < 2 * 1024 * 1024
  28. echo "total ok: ", total < 120 * 1024 * 1024