talloc2.nim 930 B

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