1.618
1.618

Reputation: 875

How many memory the bit-vector using in sbcl?

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?

Upvotes: 5

Views: 619

Answers (2)

Rainer Joswig
Rainer Joswig

Reputation: 139261

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

Upvotes: 7

Xach
Xach

Reputation: 11854

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.

Upvotes: 6

Related Questions