3 ms·
> in using an immutable screen buffer, a change between frames results in allocation of a full buffer rather than overwriting memory within the buffer That’s a
by knubie 5y ago
> in using an immutable screen buffer, a change between frames results in allocation of a full buffer rather than overwriting memory within the buffer
That’s actually not how clojure’s immutable data structures work. They use structural sharing, so only the portion that changes (roughly) needs new memory allocated, and only the parts that changed get garbage collected, so it is a bit more efficient than that.
- ben-schaaf 5y agoYou can't deallocate part of a frame buffer, it's a single allocation. Unless every pixel is individually allocated, which would clearly be insane.
- knubie 5y agoI'm explaining how clojure's data structures are different from OP's screen buffer example.
- __s 5y agoBut if your frame buffer is text, you can store the text in a rope data structure like JS vms do So you don't necessarily have an allocation for every single character, but you're still able to share memory between buffers I've implemented a game engine with immutability (makes for fast cloning in AI search) where much of the game state is shared between clones. With reference counting it also means if there's a unique reference being modified then no copy is made. This same trick is used by Python to optimize string concatenation