trealloc.nim 515 B

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