Feature #17851


ruby extension for memoryview

Added by dsisnero (Dominic Sisneros) about 1 year ago. Updated about 1 year ago.

Target version:


add an extension to ruby for memoryview - (just like Fiddle::MemoryView but in ruby assuming Fiddle::MemoryView gets slices)
add a method in Kernel to get initialize a memoryview on an object that is a c memoryview

lets say we want to partially copy a file - minus the first KB

f ='test.txt', 'rb') do |f|
  content =
  content_to_write = memoryview(content)[1024..-1]   # here is what I want new -it will use the same memory as content just pointers
  puts "content length #{content.size} - content_to_write length #{content_to_write.size}"'output.txt','wb') do |f2|
     f2.write(content_to_write)                      # if we have #17832 this will write to file without copying 

If we have memoryview extension in ruby we can use less memory because we are no longer copying Strings when doing slices

Related issues 1 (0 open1 closed)

Related to Ruby master - Feature #17831: add slice method to Fiddle::MemoryViewThird Party's IssueActions
Actions #1

Updated by jeremyevans0 (Jeremy Evans) about 1 year ago

  • Backport deleted (2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN)
  • Tracker changed from Bug to Feature

Updated by Eregon (Benoit Daloze) about 1 year ago

I think Fiddle::MemoryView is not needed for this.
String#[] can already avoid copying, on CRuby I think only if taking a substring until the end (the case here).

Also if Fiddle::MemoryView returns a mutable/non-read-only view, it seems very difficult to support while not making a copy and keeping the Ruby String working.

Finally, a method on Kernel is most likely not acceptable, we'd want a proper namespace like on Fiddle::MemoryView or so.

Actions #3

Updated by Eregon (Benoit Daloze) about 1 year ago

  • Related to Feature #17831: add slice method to Fiddle::MemoryView added

Also available in: Atom PDF