[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: Errno::ENOMEM reading a device in Ruby, not in Java thou

Yukihiro Matsumoto

1/29/2009 9:06:00 PM

Hi,

In message "Re: Errno::ENOMEM reading a device in Ruby, not in Java thou"
on Fri, 30 Jan 2009 05:40:45 +0900, Roger Pack <rogerpack2005@gmail.com> writes:

|> I didn't know that. In that case, you have to pre-allocate reading
|> buffer (string) and specify it to read method.
|
|Interesting.
|Perhaps somebody with brighter eyes can help me out with this?
|[how to?]
|
|>> b = 'a'*129000
|>> a.read b

You have to specify the optional second argument:

---------------------------------------------------------------- IO#read
ios.read([length [, buffer]]) => string, buffer, or nil
------------------------------------------------------------------------
Reads at most _length_ bytes from the I/O stream, or to the end of
file if _length_ is omitted or is +nil+. _length_ must be a
non-negative integer or nil. If the optional _buffer_ argument is
present, it must reference a String, which will receive the data.

b = " "*65000
a.read(b.size, b)

|>> a.read 65000
|Errno::ENOMEM: Cannot allocate memory - /dev/nst2

Hmm, since read with number pre-allocate specified sized buffer, it
should work. Perhaps you have to use sysread instead of mere read,
since read method retries until exact number of bytes specified read.

matz.

1 Answer

Roger Pack

6/9/2009 10:08:00 PM

0

> b = " "*65000
> a.read(b.size, b)
>
> |>> a.read 65000
> |Errno::ENOMEM: Cannot allocate memory - /dev/nst2
>
> Hmm, since read with number pre-allocate specified sized buffer, it
> should work. Perhaps you have to use sysread instead of mere read,
> since read method retries until exact number of bytes specified read.
>
> matz.

Interesting.
with 1.9, it will read all 64K at once (not with 1.8 though--it reads 4K
blocks until it reached 64K).

sysread did work with 1.8, though

for some reason I had to use exactly 64K block size.

file.sysread(64*1024)

guess something to remember if you have to read from a tape drive.

I did notice a few of these when using 1.9

ioctl(3, SNDCTL_TMR_TIMEBASE or TCGETS, 0xbfd172a8) = -1 ENOTTY
(Inappropriate ioctl for device)

dunno if that's cause for concern or not.
Cheers!
-=r
--
Posted via http://www.ruby-....