How many memory the bit-vector using in sbcl?
Does per bit spend 1 bit memory? Does per bit spend 1 byte memory? Does per bit spend 1 word memory?
How many memory the bit-vector using in sbcl?
Does per bit spend 1 bit memory? Does per bit spend 1 byte memory? Does per bit spend 1 word memory?
From Common Lisp one can ask if there is a special array type for bit vectors:
* (UPGRADED-ARRAY-ELEMENT-TYPE 'bit)
BIT
That means that when you ask for a bit vector, then CL provides you with a bit vector and not a, say, vector with 8 bit elements.
Size of an object in SBCL
Alastair Bridgewater provided this function as an attempt to get the 'size' of an object in SBCL:
(defun get-object-size/octets (object)
(sb-sys:without-gcing
(nth-value 2 (sb-vm::reconstitute-object
(ash (logandc1 sb-vm:lowtag-mask
(sb-kernel:get-lisp-obj-address object))
(- sb-vm:n-fixnum-tag-bits))))))
* (get-object-size/octets (make-array 40 :element-type 'bit :initial-element 1))
32
* (get-object-size/octets (make-array 400 :element-type 'bit :initial-element 1))
80
* (get-object-size/octets (make-array 4000 :element-type 'bit :initial-element 1))
528
Bit vectors in SBCL are stored efficiently with one bit per bit, plus some small housekeeping overhead per vector.
They are also very efficient at bitwise operations, working a full word at a time. For example, BIT-XOR on a 64-bit platform will work on 64 bits of a bit-vector at once.
© 2022 - 2024 — McMap. All rights reserved.
(sb-ext:primitive-object-size (make-array 4000 :element-type 'bit :initial-element 1))
--> 528 – Aleedis