1. get.e

Matt Lewis wrote:
> 
> don cole wrote:
> > 
> >     What I want to achieve is to read the whole file in one fell swoop.
> > 
> > If I use gets() all the way through it works but takes longer.
> 
> gets() is probably the fasted way to read it.  get() is wholly inappropriate.
> As the docs state, it's for reading euphoria objects that have been 
> printed using print (though is also handles things like double and single
> quotes).  You don't say how you plan to store the data, but I'll assume you
> just want the lines concatenated:
> 
> }}}
<eucode>
> object in
> sequence s
> s = {}
> in = gets(fin)
> while( sequence( in ) ) do
>     s &= in
>     in = gets( fin )
> end while
> </eucode>
{{{

> I use this basic pattern all the time for reading files (though I usually
> keep each line in it's own sequence), and I've never had a problem with the
> 
> speed.  I recall one point in the past when people tried using things like
> get_bytes to speed up file IO, but didn't.  It seems that the actual
> hardware IO is the bottleneck.
> 
> Matt
> }}}
<eucode>
  object in
  sequence s
  integer fin
  fin=open("myfile.ew","r")
 s = {}
 in = gets(fin)
while( sequence( in ) ) do
     s &= in
    in = gets( fin )
 end while
 </eucode>
{{{


  Is what I'm using and you're saying that's faster than anything using get()?

Don Cole

new topic     » topic index » view message » categorize

2. Re: get.e

For what its worth, here is the routine I use to red an entire file into a
sequence...
global function ReadFile(sequence pFileName)
    integer lFH
    sequence lData

    lFH = open(pFileName,"rb")
    if lFH = -1 then
        return -1
    end if

    machine_proc(19, {lFH,-1})
    lData = repeat(0, machine_func(20, lFH))
    machine_proc(19, {lFH,0})

    for i = 1 to length(lData) do
        lData[i] = getc(lFH)
    end for
    close(lFH)

    return lData
end function



Note that machine routine 19 is 'seek' and 20 is 'where'. I did it this way to
avoid the tiny overhead of including file.e and using it's routine.

On my machine this reads a 64 Meg file in around 1.4 seconds.

-- 
Derek Parnell
Melbourne, Australia
Skype name: derek.j.parnell

new topic     » goto parent     » topic index » view message » categorize

3. Re: get.e

Derek Parnell wrote:
> 
> For what its worth, here is the routine I use to red an entire file into a
> sequence...
> }}}
<eucode>
> global function ReadFile(sequence pFileName)
>     integer lFH
>     sequence lData
> 
>     lFH = open(pFileName,"rb")
>     if lFH = -1 then
>         return -1
>     end if
> 
>     machine_proc(19, {lFH,-1})
>     lData = repeat(0, machine_func(20, lFH))
>     machine_proc(19, {lFH,0})
> 
>     for i = 1 to length(lData) do
>         lData[i] = getc(lFH)
>     end for
>     close(lFH)
> 
>     return lData
> end function
> </eucode>
{{{

> 
> 
> Note that machine routine 19 is 'seek' and 20 is 'where'. I did it this way
> to avoid the tiny overhead of including file.e and using it's routine.
> 
> On my machine this reads a 64 Meg file in around 1.4 seconds.
> 
> -- 
> Derek Parnell
> Melbourne, Australia
> Skype name: derek.j.parnell

Thanks Derek,

Don Cole

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu