mem-vector.txt 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # Block Memory Operations
  2. Function: mem-fill ptr type count value &optional (offset 0)
  3. Fill COUNT objects of TYPE, starting at PTR plus offset, with VALUE.
  4. ;; Equivalent to (but possibly more efficient than):
  5. (loop for i below count
  6. for off from offset by (%foreign-type-size type)
  7. do (setf (%mem-ref ptr type off) value))
  8. Function: mem-read-vector vector ptr type count &optional (offset 0)
  9. Copy COUNT objects of TYPE from foreign memory at PTR plus OFFSET into
  10. VECTOR. If VECTOR is not large enough to contain COUNT objects, it
  11. will copy as many objects as necessary to fill the vector. The
  12. results are undefined if the foreign memory block is not large enough
  13. to supply the data to copy.
  14. TYPE must be a built-in foreign type (integer, float, double, or
  15. pointer).
  16. Returns the number of objects copied.
  17. ;; Equivalent to (but possibly more efficient than):
  18. (loop for i below (min count (length vector))
  19. for off from offset by (%foreign-type-size type)
  20. do (setf (aref vector i) (%mem-ref ptr type off))
  21. finally (return i))
  22. Function: mem-read-c-string string ptr &optional (offset 0)
  23. Copy a null-terminated C string from PTR plus OFFSET into STRING, a
  24. Lisp string. If STRING is not large enough to contain the data at PTR
  25. it will be truncated.
  26. Returns the number of characters copied into STRING.
  27. ;; Equivalent to (but possibly more efficient than):
  28. (loop for i below (length string)
  29. for off from offset
  30. for char = (%mem-ref ptr :char off)
  31. until (zerop char)
  32. do (setf (char string i) char)
  33. finally (return i))
  34. Function: mem-write-vector vector ptr type &optional
  35. (count (length vector)) (offset 0)
  36. Copy COUNT objects from VECTOR into objects of TYPE in foreign memory,
  37. starting at PTR plus OFFSET. The results are undefined if PTR does
  38. not point to a memory block large enough to hold the data copied.
  39. TYPE must be a built-in type (integer, float, double, or pointer).
  40. Returns the number of objects copied from VECTOR to PTR.
  41. ;; Equivalent to (but possibly more efficient than):
  42. (loop for i below count
  43. for off from offset by (%foreign-type-size type)
  44. do (setf (%mem-ref ptr type off) (aref vector i))
  45. finally (return i))
  46. Function: mem-write-c-string string ptr &optional (offset 0)
  47. Copy the characters from a Lisp STRING to PTR plus OFFSET, adding a
  48. final null terminator at the end. The results are undefined if the
  49. memory at PTR is not large enough to accomodate the data.
  50. This interface is currently equivalent to MEM-WRITE-VECTOR with a TYPE
  51. of :CHAR, but will be useful when proper support for Unicode strings
  52. is implemented.