Python mmap example

89 views
Skip to first unread message

Ross Williamson

unread,
May 9, 2012, 5:49:32 PM5/9/12
to comed...@googlegroups.com
Hi all,

I'm looking over the python mmap example and am I correct in thinking that if front is larger than the buffer size then we would loose data - i.e.

front += c.comedi_get_buffer_contents(dev,subdevice) #If this becomes a number > size - should wrap around
map.seek(back%size) # Correctly finds position if back > size
for i in range(back,front,2):
    map.read(2)   #Problem here as the count would take the read to be > size and return blank?

Don't we need something like this inside the loop?:

if i == size:
  map.seek(0)




Ian Abbott

unread,
May 10, 2012, 6:14:21 AM5/10/12
to comed...@googlegroups.com
On 2012-05-09 22:49, Ross Williamson wrote:
> Hi all,
>
> I'm looking over the python mmap example and am I correct in thinking
> that if front is larger than the buffer size then we would loose data - i.e.
>
> front += c.comedi_get_buffer_contents(dev,subdevice) #If this becomes a
> number > size - should wrap around
> map.seek(back%size) # Correctly finds position if back > size
> for i in range(back,front,2):
> map.read(2) #Problem here as the count would take the read to be > size
> and return blank?

Yes, that is a problem.

> Don't we need something like this inside the loop?:
>
> if i == size:
> map.seek(0)

You're half right, but 'front' and 'back' (and therefore 'i') can be
larger than 'size'. I think the test should be either

if i%size == 0:

or

if map.tell(0) == size:

--
-=( Ian Abbott @ MEV Ltd. E-mail: <abb...@mev.co.uk> )=-
-=( Tel: +44 (0)161 477 1898 FAX: +44 (0)161 718 3587 )=-

Ian Abbott

unread,
May 10, 2012, 8:57:01 AM5/10/12
to comed...@googlegroups.com
On 2012-05-10 11:14, Ian Abbott wrote:
> On 2012-05-09 22:49, Ross Williamson wrote:
>> Hi all,
>>
>> I'm looking over the python mmap example and am I correct in thinking
>> that if front is larger than the buffer size then we would loose data - i.e.
>>
>> front += c.comedi_get_buffer_contents(dev,subdevice) #If this becomes a
>> number> size - should wrap around
>> map.seek(back%size) # Correctly finds position if back> size
>> for i in range(back,front,2):
>> map.read(2) #Problem here as the count would take the read to be> size
>> and return blank?
>
> Yes, that is a problem.
>
>> Don't we need something like this inside the loop?:
>>
>> if i == size:
>> map.seek(0)
>
> You're half right, but 'front' and 'back' (and therefore 'i') can be
> larger than 'size'. I think the test should be either
>
> if i%size == 0:
>
> or
>
> if map.tell(0) == size:

That should have been

if map.tell() == size:

Anyway, it's fixed in the master git repository now.
Reply all
Reply to author
Forward
0 new messages