On 13-01-2023 12:32, Ludovic Courtès wrote:
IIUC, if you use bytevector-slice iteratively, say:(let loop ((bv some-initial-value) (n large-number)) (if (> n 0) (loop (bytevector-slice bv 0 (bytevector-length bv)) (- n 1)) bv)) you will end up with a bytevector containing a reference to a bytevector containing a reference to ... containing a reference to the original reference, in a chain of length ≃ large-number.The ‘parent’ word is here just so the backing memory isn’t reclaimed while the slice is still alive. Whether there’s a long chain of ‘parent’ links or not makes no difference to GC performance nor to memory usage.
This is false, the opposite holds: memory usage is at least linear in the length of the chain, because the objects in the chain are pairwise non-eq?: for a chain (O_1, O_2, ..., O_n) that is alive, each object O_i in the chain is kept alive (because that's what the 'parent' link is for). Because bytevector-slice does a fresh allocation, there then are n different objects. Hence, memory usage is at least 'SCM_BYTEVECTOR_HEADER_SIZE * sizeof(scm_t_bits) * n'.
Greetings, Maxime.
OpenPGP_0x49E3EE22191725EE.asc
Description: OpenPGP public key
OpenPGP_signature
Description: OpenPGP digital signature