The "mod" and the write barrier will significantly degrade performance vs C.
Probably faster to replace "mod" with if-based wrap around but there's
nothing you can do about the write barrier.

Cheers,
Jon.

> -----Original Message-----
> From: David Allsopp [mailto:dra-n...@metastack.com]
> Sent: 02 April 2012 16:05
> To: Hongbo Zhang; Caml List
> Subject: RE: [Caml-list] How could I implement an efficient ring buffer?
> 
> Hongbo Zhang wrote:
> > Hi List,
> >     I want to implement sliding window algorithm (in place, no memory
> > copy), I wonder whether I need to write c code.
> >
> >     To make it clear and simple,
> >        In c, you can record the head pointer of the array, and do the
> > modulo operations when get and set
> >        In ocaml, it seems you have an array a of type int array,  you
> > can not do things like this *(&a+5).
> 
> Perhaps I'm missing something, but if you're planning on using arrays,
what's
> wrong with retrieving the item using the array index modulo the length of
the
> array?
> 
> i.e.
> 
> let a = [| ... or whatever ... |] in
> a.(5 mod Array.length a)
> 
> If accessing an array by index instead of by pointer worries you, then
you're
> looking at the wrong language ;o)
> 
> 
> David
> 
> 
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa-roc.inria.fr/wws/info/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs


-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Reply via email to