[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

IO#write_nonblock(string, offset) useful?

Roger Pack

9/2/2008 6:46:00 PM

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
--
Posted via http://www.ruby-....

8 Answers

Joel VanderWerf

9/2/2008 7:06:00 PM

0

Roger Pack wrote:
> 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?

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

Rob Biedenharn

9/2/2008 7:09:00 PM

0



Joel VanderWerf

9/2/2008 7:29:00 PM

0

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?

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

Todd Benson

9/2/2008 7:56:00 PM

0

On Tue, Sep 2, 2008 at 2:29 PM, Joel VanderWerf <vjoel@path.berkeley.edu> wrote:
> 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

Rob Biedenharn

9/2/2008 7:58:00 PM

0


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

> 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?
>
> --
> 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 Biedenharn http://agileconsult...
Rob@AgileConsultingLLC.com




Roger Pack

9/2/2008 8:00:00 PM

0

> 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
--
Posted via http://www.ruby-....

Joel VanderWerf

9/2/2008 8:07:00 PM

0

Roger Pack 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.

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

Roger Pack

9/2/2008 10:30:00 PM

0

> 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
--
Posted via http://www.ruby-....