[cffi-devel] Re: patch for uffi-compat

Novikov Leonid ln at bk.ru
Mon Dec 26 12:40:26 UTC 2005


Luís Oliveira wrote:

>Леонид Новиков <ln at bk.ru> writes:
>
>  
>
>>This patch accelerates work with array
>>    
>>
>
>Hi, I suspect the following patch will be even faster (though I don't
>have any numbers, do you?). Do let me know if it works for you.
>
>
>diff -rN -u cffi-luis-old/uffi-compat/uffi-compat.lisp cffi-luis-new/uffi-compat/uffi-compat.lisp
>--- cffi-luis-old/uffi-compat/uffi-compat.lisp  2005-12-14 11:02:44.000000000 +0000
>+++ cffi-luis-new/uffi-compat/uffi-compat.lisp  2005-12-21 12:00:02.000000000 +0000
>@@ -236,9 +236,12 @@
> 
> (defmacro deref-array (array type position)
>   "Dereference an array."
>-  `(cffi:mem-aref ,array (element-type
>-                          (cffi::parse-type
>-                           (convert-uffi-type ,type)))
>+  `(cffi:mem-aref ,array
>+                  ,(if (constantp type)
>+                       `',(element-type (cffi::parse-type
>+                                         (convert-uffi-type (eval type))))
>+                       `(element-type (cffi::parse-type
>+                                       (convert-uffi-type ,type)))) 
>                   ,position))
> 
> ;; UFFI's documentation on DEF-UNION is a bit scarce, I'm not sure
>
>
>  
>
Yes really this works well. However this will not help for instance in 
such event:
(defun any-func ()
     (let ((ptr (uffi:allocate-foreign-object '(:array :int 10))))
    ; some actions are produced with ptr
    (uffi:free-foreign-object ptr))
  )
Object uffi-array-type will create On each call of this functions. If 
for time of the functioning the program such call several thousand that  
computer memory ends. My patch allows to avoid this. Its main idea in 
that arrays with element one and same type and alike length has same 
type. IMHO this it is correct






More information about the cffi-devel mailing list