1. new allocate_string functions
- Posted by "Igor Kachan" <kinz at peterlink.ru> Sep 12, 2004
- 441 views
Hi, Dear EU users: There is the allocate_string() function in the standard RDS machine.e library. Try please some variations on this theme:
include machine.e object ok -- without type_check global function pointer_1(sequence s) atom a s &= 0 a = machine_func(16,length(s)) if a then poke(a, s) end if return a end function global function pointer_2(sequence s) atom a a = machine_func(16,length(s) + 1) if a then poke(a, s & 0) end if return a end function integer l atom a global function pointer_3(sequence s) l = length(s) + 1 a = machine_func(16, l) if a then poke(a, s & 0) end if return a end function global function pointer_4(sequence s) l = length(s) a = machine_func(16, l+1) if a then poke(a, s) poke(a+l, 0) -- Thanks to Aku end if return a end function global function pointer_5(sequence s) atom a integer l l = length(s) a = machine_func(16, l+1) if a then poke(a, s) poke(a+l, 0) -- Thanks to Aku end if return a end function sequence test test = "proba pera iz gusinogo kryla" --1 & "proba pera iz gusinogo kryla" --2 & "proba pera iz gusinogo kryla" --3 atom T, A, N N=10000000 ---1 T= time() for i=1 to N do A = allocate_string(test) machine_proc(17, A) end for A = time() ? A - T ---2 T= time() for i=1 to N do A = pointer_1(test) machine_proc(17, A) end for A = time() ? A - T ---3 T= time() for i=1 to N do A = pointer_2(test) machine_proc(17, A) end for A = time() ? A - T ---4 T= time() for i=1 to N do A = pointer_3(test) machine_proc(17, A) end for A = time() ? A - T ---5 T= time() for i=1 to N do A = pointer_4(test) machine_proc(17, A) end for A = time() ? A - T ---6 T= time() for i=1 to N do A = pointer_5(test) machine_proc(17, A) end for A = time() ? A - T ok = getc(0)
I have the following results on P4 1.8GHz: 1 & 2 & 3 1&2&3 without type_check allocate_string() 12.16 14.428 15.961 15.514 pointer_1() 10.206 12.825 15.517 15.228 -- simplest one pointer_2() 10.141 12.977 15.471 15.013 pointer_3() 10.91 13.353 15.818 15.5 pointer_4() 8.123 10.154 12.145 11.678 -- fastest one pointer_5() 8.327 10.347 12.097 11.781 These new functions have the automated type check for the machine_func() call - length(s), so they do not need any wrapped calls (via allocate()), it seems to me. Use on your own risk! Regards, Igor Kachan kinz at peterlink.ru
2. Re: new allocate_string functions
- Posted by Robert Craig <rds at RapidEuphoria.com> Sep 13, 2004
- 417 views
Igor Kachan wrote: > > Hi, Dear EU users: > > There is the allocate_string() function > in the standard RDS machine.e library. > > Try please some variations on this theme: OK, it's not quite as readable, but you've convinced me:
global function allocate_string(sequence s) -- create a C-style null-terminated string in memory atom mem mem = machine_func(M_ALLOC, length(s) + 1) -- Thanks to Igor if mem then poke(mem, s) poke(mem+length(s), 0) -- Thanks to Aku end if return mem end function
Regards, Rob Craig Rapid Deployment Software http://www.RapidEuphoria.com
3. Re: new allocate_string functions
- Posted by Bernard Ryan <xotron at bluefrog.com> Sep 13, 2004
- 423 views
Robert Craig wrote: > > Igor Kachan wrote: > > > > Hi, Dear EU users: > > > > There is the allocate_string() function > > in the standard RDS machine.e library. > > > > Try please some variations on this theme: > > OK, it's not quite as readable, but you've convinced me: > > }}} <eucode> > global function allocate_string(sequence s) > -- create a C-style null-terminated string in memory > atom mem > > mem = machine_func(M_ALLOC, length(s) + 1) -- Thanks to Igor > if mem then > poke(mem, s) > poke(mem+length(s), 0) -- Thanks to Aku > end if > return mem > end function > </eucode> {{{ > > Regards, > Rob Craig > Rapid Deployment Software > <a href="http://www.RapidEuphoria.com">http://www.RapidEuphoria.com</a> > Rob: Can't you do this ?
if mem then poke(mem, s&0) -- poke(mem+length(s), 0) -- Thanks to Aku end if
Bernie My files in archive: http://www.rapideuphoria.com/w32engin.zip http://www.rapideuphoria.com/mixedlib.zip http://www.rapideuphoria.com/eu_engin.zip http://www.rapideuphoria.com/win32eru.zip
4. Re: new allocate_string functions
- Posted by Derek Parnell <ddparnell at bigpond.com> Sep 13, 2004
- 405 views
Robert Craig wrote: > > Igor Kachan wrote: > > > > Hi, Dear EU users: > > > > There is the allocate_string() function > > in the standard RDS machine.e library. > > > > Try please some variations on this theme: > > OK, it's not quite as readable, but you've convinced me: > Well if we are going to nit-pick then int_to_bytes() could be made faster if coded as ...
function int_to_bytes(atom a) poke4(mem,a) return peek({mem,4}) end function
and moved down after the 'mem=allocate(4)' line that's already there. It all depends on if the function must always return INTEL-formatted integers or not. -- Derek Parnell Melbourne, Australia
5. Re: new allocate_string functions
- Posted by Derek Parnell <ddparnell at bigpond.com> Sep 13, 2004
- 403 views
Bernard Ryan wrote: > > Robert Craig wrote: > > [snip] > > Rob: > > Can't you do this ? > > }}} <eucode> > if mem then > poke(mem, s&0) > -- poke(mem+length(s), 0) -- Thanks to Aku > end if > </eucode> {{{ Yes, but its a lot slower. First the 's&0' must create a new sequence built by appending 0 to s. Then we get to copy that temporary sequence to RAM, then we get to delete the temporary sequence. -- Derek Parnell Melbourne, Australia