trealloc.nim 527 B

123456789101112131415161718192021222324
  1. discard """
  2. output: '''success'''
  3. joinable: false
  4. disabled: "openbsd"
  5. """
  6. # bug #4818
  7. # Test that this completes without OOM.
  8. const BUFFER_SIZE = 5000
  9. var buffer = cast[ptr uint16](alloc(BUFFER_SIZE))
  10. var total_size: int64 = 0
  11. for i in 0 .. 1000:
  12. let size = BUFFER_SIZE * i
  13. #echo "requesting ", size
  14. total_size += size.int64
  15. buffer = cast[ptr uint16](realloc(buffer, size))
  16. #echo totalSize, " total: ", getTotalMem(), " occupied: ", getOccupiedMem(), " free: ", getFreeMem()
  17. dealloc(buffer)
  18. echo "success"