talloc2.nim 854 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. discard """
  2. disabled: "windows"
  3. joinable: false
  4. """
  5. # appveyor is "out of memory"
  6. const
  7. nmax = 2*1024*1024*1024
  8. proc test(n: int) =
  9. var a = alloc0(9999)
  10. var t = cast[ptr UncheckedArray[int8]](alloc(n))
  11. var b = alloc0(9999)
  12. t[0] = 1
  13. t[1] = 2
  14. t[n-2] = 3
  15. t[n-1] = 4
  16. dealloc(a)
  17. dealloc(t)
  18. dealloc(b)
  19. # allocator adds 48 bytes to BigChunk
  20. # BigChunk allocator edges at 2^n * (1 - s) for s = [1..32]/64
  21. proc test2(n: int) =
  22. let d = n div 256 # cover edges and more
  23. for i in countdown(128,1):
  24. for j in [-4096, -64, -49, -48, -47, -32, 0, 4096]:
  25. let b = n + j - i*d
  26. if b>0 and b<=nmax:
  27. test(b)
  28. #echo b, ": ", getTotalMem(), " ", getOccupiedMem(), " ", getFreeMem()
  29. proc test3 =
  30. var n = 1
  31. while n <= nmax:
  32. test2(n)
  33. n *= 2
  34. n = nmax
  35. while n >= 1:
  36. test2(n)
  37. n = n div 2
  38. test3()