[request] efficient way to copy from bytevectors to malloc()ed memory

Bug #369255 reported by Andreas Rottmann
2
Affects Status Importance Assigned to Milestone
Ikarus Scheme
Fix Committed
Medium
Abdulaziz Ghuloum

Bug Description

It would be nice to have a fast way to move data from Scheme
bytevectors to C-accessible memory and vice-versa. I've attached a
patch that adds a procedure called `memcpy' to the FFI that does
this.

In a simple synthetic benchmark, the speed gain ranges from a factor
of ~3 (copying 8 bytes) to a factor of ~240 (copying 64KiB); compared
against a naive Scheme implementation of memcpy using byte operations
on bytevectors and FFI pointers.

In a quasi-real-live scenario (a webserver implemented using
libsoup[0] via the FFI), just switching to the attached implementation
of memcpy instead of using the naive one implemented in Scheme doubled
the throughput in case of serving a 50KiB static file.

[0] http://live.gnome.org/LibSoup

Related branches

Revision history for this message
Andreas Rottmann (rotty) wrote :
Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote :

Looks good. Patched in revision 1771. Thanks.

Changed in ikarus:
assignee: nobody → Abdulaziz Ghuloum (aghuloum)
importance: Undecided → Medium
status: New → Fix Committed
Revision history for this message
Derick Eddington (derick-eddington) wrote : Re: [Bug 369255] Re: [request] efficient way to copy from bytevectors to malloc()ed memory

A couple typos:

=== modified file 'scheme/ikarus.pointers.ss'
--- scheme/ikarus.pointers.ss 2009-04-30 09:35:49 +0000
+++ scheme/ikarus.pointers.ss 2009-05-01 05:02:52 +0000
@@ -127,7 +127,7 @@
     (unless (and (fixnum? src-offset) (fx>=? src-offset 0))
       (die who "not a positive fixnum" src-offset))
     (unless (and (fixnum? count) (fx>=? count 0))
- (die who "not a postive fixnum" count))
+ (die who "not a positive fixnum" count))
     (cond ((and (pointer? dst) (bytevector? src))
            (unless (fx<=? (fx+ src-offset count) (bytevector-length src))
              (die who "source bytevector length exceeded"
@@ -142,7 +142,7 @@
                          dst dst-offset (pointer+ src src-offset) count))
           (else
            (die who "destination and source not a bytevector/pointer pair"
- dst dst))))
+ dst src))))

   ;;; getters and setters

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.