[gambit-list] Does "time" report an accurate count of the number of bytes allocated?

Marc Feeley feeley at iro.umontreal.ca
Fri Dec 21 14:27:06 EST 2012


On 2012-12-21, at 12:50 AM, Bradley Lucier <lucier at math.purdue.edu> wrote:

> More generally, can the number of bytes reported be confused by stack manipulation?  I.e., if things go on the stack, but then the stack is unwound, does "time" report any allocation?

"time" does report the space used by stack frames which migrate to the heap, but not those in the bounded size stack area.  That's because stack frames are usually reclaimed when functions return and it would be confusing to the programmer trying to make sense of the space allocation reports.

In other words, the space allocated for stack frames is ignored unless the stack area overflows (a deep recursion will cause the stack frames to migrate to the heap) or the current continuation is captured.

Here are some examples:

(declare (standard-bindings) (fixnum) (not safe))

(define (loop n thunk) (if (= n 0) (thunk) (+ 1 (loop (- n 1) thunk))))

(time (loop 10000 (lambda () 0)))    ;; no bytes allocated
(time (loop 11000 (lambda () 0)))    ;; no bytes allocated
(time (loop 12000 (lambda () 0)))    ;; no bytes allocated
(time (loop 13000 (lambda () 0)))    ;; no bytes allocated
(time (loop 14000 (lambda () 0)))    ;; no bytes allocated
(time (loop 15000 (lambda () 0)))    ;; 917120 bytes allocated
(time (loop 16000 (lambda () 0)))    ;; 917504 bytes allocated

(time (loop 100 (lambda () (##continuation-capture list) 0)))    ;; 6768 bytes allocated
(time (loop 1000 (lambda () (##continuation-capture list) 0)))   ;; 64368 bytes allocated
(time (loop 10000 (lambda () (##continuation-capture list) 0)))  ;; 640368 bytes allocated
(time (loop 100000 (lambda () (##continuation-capture list) 0))) ;; 6402608 bytes allocated

Marc




More information about the Gambit-list mailing list