How many memory the bit-vector using in sbcl?
Asked Answered
A

2

5

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?

Affiche answered 4/3, 2017 at 8:53 Comment(0)
W
7

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
Windsor answered 5/3, 2017 at 8:33 Comment(1)
The "bug" report involving Alastair Bridgewater (bugs.launchpad.net/sbcl/+bug/1636910) seems to have led to an upgrade of SBCL: (sb-ext:primitive-object-size (make-array 4000 :element-type 'bit :initial-element 1)) --> 528Aleedis
A
6

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.

Audie answered 4/3, 2017 at 21:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.