summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEkaitz Zarraga <ekaitz@elenq.tech>2022-07-19 15:58:45 +0200
committerEkaitz Zarraga <ekaitz@elenq.tech>2022-07-19 15:58:45 +0200
commit0b02de8d06856ad492b70584d5588ffd1449248b (patch)
tree99b5ca5e2054c8bc0c60db37b18fc46e9f76a640
parent95b1e787db0b31834e79c0a5186c1fa571b3c613 (diff)
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.
-rw-r--r--bytepusher.scm25
1 files 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))