[Gambas-user] file question

James Hatridge James.Hatridge at ...17...
Thu Oct 12 16:00:35 CEST 2006


Hi Christopher et al...

Ok, count me a bit slow, I think I understand. But can you show me a bit of 
code? (code I understand better) :)

Thanks,

JIM
On Wednesday 11 October 2006 18:31, Christopher Brian Jack wrote:
> On Wed, 11 Oct 2006, James Hatridge wrote:
> > Hi all
> >
> > Is there anyway I can set up a buffer or file so that when its full the
> > oldest part is dropped and newst is kept?
> >
> > The idea I have is a music buffer that holds X minutes of audio when the
> > buffer is full it will push out the old and add the new. Is this do-able?
> >
> > Thanks,
> >
> > JIM
>
> The solution to your problem is a ring buffer.
>
> To use a ring buffer split your main buffer into sequential chunks,
> maintaining a head and tail position in the buffer.  If the head and tail
> indices are zero-based (0 indicates the first chunk) then you can use x
> MOD NumberOfChunks to get the wraparound effect needed for the index
> arithmetic.  The explanation below uses MOD and hence assumes zero-based
> indices.
>
> When the buffer is initialized  head=0, tail=0, status="empty"
>
> 1.  To add to the buffer first make sure the status is not "full" (throw a
> football if it is) then increase the head with head=(head+1) MOD
> BufferChunkCount if this makes head=tail then set status to "full" and
> throw a football.  If head!=tail then you can go ahead and fill the chunk
> now indexed by head.
>
> 2.  To pull from the buffer first check that the buffer state is not
> "empty" and throw a football if it is.  Transfer the chunk to whatever
> needs it then increase the tail by one with tail=(tail+1) MOD
> BufferChunkCount.  Appropriately setting the status to "empty" if the
> condition tail=head is true after increasing the tail.
>
> 3. If the accesses to the buffer may be threaded then the head and tail
> check-and-change need to be done within semaphores or with a locking
> mechanism to make them atomic/serialized (only one thing accesses the
> head/tail indices at a time).  Head needs to bumped before writing the
> data and tail must only be bumped after the chunk is transferred to
> whatever is using the data.
>
> .=================================================.
>
> |  Christopher BRIAN Jack aka "Gau of the Veldt"  |
>
> +================================================='
>
> | oevna at ...1544...
>
> `=================================================-
> Hi Spambots, my email address is sputnik at ...1334...
> Hi Humans, my email address uses rot13 cipher
>
>
> -------------------------------------------------------------------------
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job
> easier Download IBM WebSphere Application Server v.1.0.1 based on Apache
> Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user

-- 
Jim Hatridge
Linux User #88484
------------------------------------------------------     
              WartHog Bulletin
          Info about new German Stamps
   http://www.fuzzybunnymilitia.org/~hatridge/bulletin/index.php

            Viel Feind -- Viel Ehr'
      Anti-US Propaganda stamp collection
  http://www.fuzzybunnymilitia.org/~hatridge/collection/index.php




More information about the User mailing list