Reputation: 6189
In DrRacket
I can set a memory limit using the GUI. However, I find the editor not sooo good and want to use another editor of my choice. But how do I specify the memory limit then?
I can think of two possibilities, but couldn't find anything about either of these:
racket
(not DrRacket GUI tool, but the REPL on command line) give it some arguments to specify the limitUpvotes: 5
Views: 2390
Reputation: 844
See custodians.
For example:
#lang racket
;; Set limit
(custodian-limit-memory
(current-custodian) (* 2 1024 1024))
(define x (make-bytes (* 4 1024 1024)))
Result of this code is 'out of memory'.
Upvotes: 11
Reputation: 2002
At the beginning of the code, you can set a memory limit for the module. (docs)
#lang racket/base
(define MAX-BYTES 1000)
(custodian-limit-memory (current-custodian) MAX-BYTES)
....
I don't know a straightforward command-line solution, but you can call custodian-limit-memory
in your racketrc file to set a limit for the REPL.
See also racket/sandbox, especially call-with-limits
.
Upvotes: 7