talloc2.nim 955 B

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