Re: Sequence slicing

new topic     » goto parent     » topic index » view thread      » older message » newer message

This brings to mind the way the BIOS handles the keyboard buffer.
1.  Decide how much space you need for your buffer and allocate a sequence that
size using repeat().
2.  Declare two integers that are used as subscripts that mark the beginning and
ending of the data.  When they are equal, the buffer is empty.
3.  Make all subscript calculations modulo of the size.  You have a circular
buffer, so that the byte after the last one is the first one.

The data keeps going round and round, but you don't have to free and allocate at
all.  An enhancement of this technique would be code to detect when the buffer is
about to overflow, and in that case add more space to it (permanently).

Louis.

*********** REPLY SEPARATOR  ***********

On 10/22/2003 at 4:05 PM Robert Craig wrote:

>
>
>Daniel Kluss wrote:
>> Question for Rob, is the below accurate, sounds like it to me. Could this
>> interfere with the
>> "If a is very large, and there are no other references to
>> the same sequence, this statement will be extremely fast.
>> Euphoria will simply update the length of a,
>> without copying any elements or allocating/deallocating any space."
>>
>> you said before.
>> What should I do about it, would just assigning the length to a var then
>the
>> slice make it faster? or not?
>
>You should look at:
>
>    http://www.rapideuphoria.com/perform.htm
>
>in the section "Saving Results in Variables" about half way down.
>Carl White suggested something similar.
>
>Here's the example I give:
>==============================================================
>When you have a sequence with multiple levels of subscripting,
>it is faster to change code like:
>            for i = 1 to 1000 do
>                y[a][i] = y[a][i]+1
>            end for
>
>to:
>            ya = y[a]
>            for i = 1 to 1000 do
>                ya[i] = ya[i] + 1
>            end for
>            y[a] = ya
>
>So you are doing 2 subscript operations per iteration of the loop,
>rather than 4. The operations, ya = y[a] and y[a] = ya are very cheap.
>They just copy a pointer. They don't copy a whole sequence.
>==============================================================
>
>In your case, you have 4 subscripts, so the payoff would be
>even bigger. Also, the internal slicing optimization
>I mentioned before might work better with a simpler statement.
>
>Another idea is to avoid shortening the sequence all the time,
>but just use a variable to remember how big it really
>should be at the moment. That will cut down on the
>frequent allocation/deallocation of space.
>
>Regards,
>    Rob Craig
>    Rapid Deployment Software
>    http://www.RapidEuphoria.com

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu