IO#write_nonblock(string, offset) useful?

Was asked to repost this under a separate thread, so here it is!

Currently we have
IO#write_nonblock(string) [writes as much of the string as currently
possible]

What I was thinking would be useful would be
IO#write_nonblock(string, offset) [starts the write at offset bytes into
the string].

Would anybody else find this useful?
Thanks!
-=R

Roger P. wrote:

Would anybody else find this useful?
Thanks!

With COW strings, is this really needed?

s = (0…9).to_a.to_s * 1000000
sa = (1…10000).map {|i| s[i…-1]}
puts cat /proc/#{$$}/status[/VmRSS:\s*(.*)/,1] # 13292 kB

Is there a reason other than saving memory and avoiding a #slice call?

Roger P. wrote:

puts cat /proc/#{$$}/status[/VmRSS:\s*(.*)/,1] # 13292 kB
Is there a reason other than saving memory and avoiding a #slice call?

Those would be the reasons I’d consider it useful–to save on CPU and
RAM [since it would avoid having to create all those extra objects]. I
think that’s what you were pointing out?

It’s just that those extra objects are fairly small, due to
copy-on-write… just the 20 byte ruby RString object for each slice
rather than a copy of the whole 1Mb string you are trying to send. They
share the 1Mb string data.

puts cat /proc/#{$$}/status[/VmRSS:\s*(.*)/,1] # 13292 kB
Is there a reason other than saving memory and avoiding a #slice call?

Those would be the reasons I’d consider it useful–to save on CPU and
RAM [since it would avoid having to create all those extra objects]. I
think that’s what you were pointing out?

Thanks!
-=R

Rob B. wrote:

Rob, are you aware that your message body is empty, at least on
ruby-talk. Are you posting from the forum or newsgroup?

On Tue, Sep 2, 2008 at 2:29 PM, Joel VanderWerf
[email protected] wrote:

Rob B. wrote:

Rob, are you aware that your message body is empty, at least on ruby-talk.
Are you posting from the forum or newsgroup?

Hi Rob,

i’ve noticed loss of the message with some of you other posts, too,
the most recent group starting from the Chris P. tutorial thread.

Todd

It’s just that those extra objects are fairly small, due to
copy-on-write… just the 20 byte ruby RString object for each slice
rather than a copy of the whole 1Mb string you are trying to send. They
share the 1Mb string data.

Fascinating. Thanks for pointing that out. I guess that being the case
then it’d be only a small improvement–10,000 slices on my machine takes
0.02s and calls the GC twice, so…there’s some room for improvement,
but it’s probably not a bottleneck.]
Thanks!
-=R

On Sep 2, 2008, at 3:29 PM, Joel VanderWerf wrote:

Rob B. wrote:

Rob, are you aware that your message body is empty, at least on ruby-
talk. Are you posting from the forum or newsgroup?


vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

From email (therefore the newsgroup). This happens when I forget to
uncheck the “digitally signed” option. What I meant to say was:

I presume that the IO#write_nonblock returns the number of bytes
written (which the write(2) man page says, but is only implied by the
rdoc).

Assuming this is the case (and the method will become
IO#write_nonblock(string, offset=0)), I’d think that this was a good
idea. (Even though I’ve never had to use it.)

-Rob

Rob B. http://agileconsultingllc.com
[email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs