guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Add 'bytevector-slice'.


From: Maxime Devos
Subject: Re: [PATCH] Add 'bytevector-slice'.
Date: Fri, 13 Jan 2023 12:56:13 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0

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.

Attachment: OpenPGP_0x49E3EE22191725EE.asc
Description: OpenPGP public key

Attachment: OpenPGP_signature
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]