Method: (ALLOCATE-BLOCK FREE-LIST-HEAP)

Source

(defmethod allocate-block ((heap free-list-heap) 
                           &key (size (min-block-size heap)) (expand t))
  ;; We don't bother to do something with the unused part of the block.
  ;; Each block will be at least half full anyway (otherwise a block
  ;; from another free list would have been allocated).  On average,
  ;; I suppose each block will be 75% full. It would be possible to
  ;; give the remaining 25% to a free list of a lower size class, but
  ;; I'm not sure that is worth the extra complexity (or the extra time).
  (let* ((size-class (size-class size heap))
         (block (free-list-start heap size-class)))
    ;; Expand free list when it's empty.
    (when (free-list-empty-p size-class heap)
      (if expand
          (setq block (expand-free-list size-class heap))
        (return-from allocate-block
          (values nil 0))))
    ;; Unhook the block from the free list
    ;; (the block header of an unused block contains a pointer to the
    ;; next unused block).
    (let ((next-block (block-header block heap)))
      (setf (free-list-start heap size-class) next-block))
    ;; Put block size (including the size of header and unused part)
    ;; into header.
    (setf (block-size block heap) (size-class-block-size size-class heap))
    ;; Return the block.
    (values block size)))
Source Context