IO#write_nonblock(string, offset) useful?

R

Roger Pack

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
 
J

Joel VanderWerf

Roger said:
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!

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?
 
J

Joel VanderWerf

Rob Biedenharn wrote:

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

Todd Benson

Rob Biedenharn 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 Pine tutorial thread.

Todd
 
R

Rob Biedenharn

Rob Biedenharn wrote:

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

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 Biedenharn http://agileconsultingllc.com
(e-mail address removed)
 
R

Roger Pack

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
 
J

Joel VanderWerf

Roger said:
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.
 
R

Roger Pack

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,145
Messages
2,570,826
Members
47,371
Latest member
Brkaa

Latest Threads

Top