Implement zero copy I/O reads into a FFI AbstractMemory  destination buffer
---------------------------------------------------------------------------

                 Key: JRUBY-3636
                 URL: http://jira.codehaus.org/browse/JRUBY-3636
             Project: JRuby
          Issue Type: Improvement
            Reporter: Wayne Meissner
            Assignee: Thomas E Enebo
             Fix For: JRuby 1.x+



Currently, to read data from an IO stream into a FFI memory buffer, the data 
must be first read into a ruby string instance, then copied into the FFI buffer.

The number of copies is actually more than that, since NIO will first read into 
a direct buffer (native memory), then copied to the ChannelStream buffer (if 
the read size is less than 4K), then copied again to the String byte array.  

In the best case, three copies could be eliminated from the total sequence, if 
the FFI buffer is also native memory.  Worst case, only two copies are 
eliminated.

For now, a simple API that mimics the C read(2) interface can be supplied in 
the FFI namespace to abstract the read process, which we can replace later with 
one that eliminates the extra copying.
e.g.
{code:title=io.rb}
  def self.read(io, buf, len)
      tmp = io.read(len)
      return -1 unless tmp
      buf.put_bytes(0, tmp)
      tmp.length
    end
{code}



-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to