Function: CBUFFER-RESIZE

Documentation

resizes cbuffer by creating a new one and copying the data along. if new-size < size then buffer may be truncated

Source

(defun cbuffer-resize (buf new-size)
  "resizes cbuffer by creating a new one and copying the data along.
   if new-size < size then buffer may be truncated"
  (let ((old-data (cbuffer-data buf))
	(old-length (cbuffer-length buf))
	(new-data (foreign-alloc :uchar :count new-size))
	(size (if  (<= (cbuffer-size buf) new-size)
		   (cbuffer-size buf)
		   new-size)))
    (setf (cbuffer-data buf) (memcpy new-data (cbuffer-data buf) size)
	  (cbuffer-length buf) new-size)
    ;;try to add the old data-buffer to pool
    (free-cbuffer (make-cbuffer-from-pointer old-data old-length))
    buf))
Source Context