From 0b02de8d06856ad492b70584d5588ffd1449248b Mon Sep 17 00:00:00 2001 From: Ekaitz Zarraga Date: Tue, 19 Jul 2022 15:58:45 +0200 Subject: Avoid memory allocations! With this change we avoid all memory allocations. Everything is pre-allocated. It makes the frame-rate stay steady with no drops produced by the GC. In order to test this, `gcprof` can be used from `statprof` module. --- bytepusher.scm | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/bytepusher.scm b/bytepusher.scm index 1182f48..4c8671b 100644 --- a/bytepusher.scm +++ b/bytepusher.scm @@ -135,18 +135,19 @@ ;; rendering ---- -(define (get-pixels) - (let* ((initial (get-initial-pixel)) - (len (* width height)) - (base (make-bytevector len)) - (final (make-bytevector (* 4 len)))) - (let loop ((i 0)) - (bytevector-u32-set! final - (* 4 i) - (pixel->color-fast (get-byte (+ i initial))) - (endianness big)) - (unless (= i (- len 1)) (loop (+ 1 i)))) - final)) +(define get-pixels + ((lambda () + (define len (* width height)) + (define final (make-bytevector (* 4 len))) + (lambda () + (let* ((initial (get-initial-pixel))) + (let loop ((i 0)) + (bytevector-u32-set! final + (* 4 i) + (pixel->color-fast (get-byte (+ i initial))) + (endianness big)) + (unless (= i (- len 1)) (loop (+ 1 i)))) + final))))) (define (make-display-texture renderer) (make-texture renderer 'argb8888 'streaming width height)) -- cgit v1.2.3