Implementing a circular buffer - which approach works best?

I'm just implementing a circular buffer (or a circular queue, to be precise). Now I wonder which is better for wrapping around when inserting:
Using the modulo operator or using some variable to store the insertionPoint and incrementing it after each insert?
Does it make any difference in performance / readability?
Greets, Oliver

Trollhorn wrote:
Uh, that article is really nice... thanks...Is that sarcasm, or is it "prob sol"?
My suggestion would simply be: Why roll your own, when you can just use a standard implementation provided by the JDK (you do know about the java.util.Queue interface and can find standard classes which implement it, right?).
So is this just for an academic exercise, or are you one of those premature optimizer kinda guys feeling the need to eek out every last millisecond of processing and/or save every last byte of memory? And maybe you fear the reaper (garbage collector) too.
I don't see a real need for a "circular queue". Circular buffers, circular lists yes (where you iterate over it in a circular fashion), but when I think of a queue I think of FIFO pushing and popping elements, not iterating over it.

Similar Messages

  • Which itrip works best with the nano 7th generation?

    Which itrip works best with the nano 7th generation?

    If you have a budget over the 90$, i schould go for bose "in ears", they seems to produce a really good sound quality (even the basses) and they filtering the noise around you.

  • External control unit - which one works best?

    i would like to buy an external control unit. which one works best with the final cut studio apps? as far as i know, there are three competitors, being:
    TASCAM 1802, MACKIE CONTROL and Digidesign...
    I would like to use the unit mainly for audio mixing and Transport functions. Maybe use some function keys for shortcuts... if the unit can be used also in Sound track pro it would not hurt But my major work is in FCP
    thanks for your input!

    I'd buy the Tascam 1802 as my control surface. Actually I'm saving my pennies to get one.
    I have a Mackie Onyx 1640 with the Firewire card and I love it to pieces as a field mixer. But I can't get it to work well with my apps as a control surface. Maybe I should check and see if Mackie has improved the software.
    But I'd go with the Tascam for FCP control surface use. You might get away with one of their smaller models if you don't need that many faders.
    Save some money that way, maybe. Leave you more to send to Apple, MOTU, DigiDesign, Bias, and Waves for software upgrades. I mean, we all understand that those folks need our money way more than we do, right? Heh, heh, heh...
    Good luck in your search.

  • Which headset work best for iPad Air

    Which headset work best for iPad Air

    This can be highly subjective. I would pick a few models that you think you'd like, then read the reviews at the Apple Store link that Diavonex directed you to. Also read the reviews on Amazon.com as well to get a feel for a few models and what kind of sound they can produce.
    Back to the "subjective" aspect I mentioned...when the Apple Ear Pods were released (they now come standard with all new iPhones), I had an iPhone 4 at the time and had the older headphones (the new Ear Pods were introduced/released with the iPhone 5). I heard great things about them and almost purchased a set when they went on sale as a stand-alone item but I decided not to. When I upgraded my phone to an iPhone 5, I got them included with the new phone. Great, I thought...well, after trying them, I hated them and I still do. They produce way too much bass for my personal taste and sound boomy. I much prefer the older model. It's just personal preference.
    Read the reviews and see if they describe how the headphones sound...boomy, tinny, clear, muddy, etc and try to match that to what your preference may be.

  • I am considering an IPhone5 which I want to "tether" to my laptop and IPad. Does anyone know which network works best. TMobile tell me that they will only tether upto 1GB data, will this be sufficient?

    I am considering an IPhone5 which I want to "tether" to my laptop and Ipad. Does anyone know which network works best. TMobile tell me that they will only tether upto 1GB of data, will this be sufficient?

    I have the AT&T family plan for use with my laptop, iPhone an iPad with 6GB per month. I tend to use the tethering far more often with the MacBook Pro than the iPad (mine has cellular) and I don't think I've had any month where 1 GB would have been sufficient for tethering. Do they have a plan where they will let you pay for additional tethering? If so I would go to at last 2 GB.
    Or look into AT&T.

  • Which ipad works best with cellular networks in Russia?

    I want to get an iPad that will work with the Russian cellular networks. Which model is best? Does it need any special configuring in oredr to work in both Russia ans the US?

    Yes, it should work with no problems, but the warranty will not be valid in Italy. Any warranty claim or service will need to be done in the US.

  • Which combodrive works best with the mega 180?

    hi..
    i think i will buy a new optical drive for my mega 180. now i wonder which combo drive that works best with it?

    have a look in this post Mega 865 Optical Drive Compatibility List. Will apply to all Megas  

  • Street atlas front page - which one works best?

    We are about to publish 2nd edition of the Trondheim region street atlas.
    We would very much apprechiate feedback on a few front page proposals. Which do you think work the best.
    We sell nearly 1000 of them every year.
    (And please ignore the  glitches on the word "kartbok", it's a bug in the jpeg export.)

    Netherlands huh!
    Quiet simple indeed, looks like the old publish and subcribe feature, but...
    As you can see in my earlier post it's a Citymap, this means i've got hundreds of streetnames all over the place..
    place it in several documents one say for each region.
    Oké, let's get it right, I Place (link) the original AI file in several "documents" either illustrator or indesign.
    This means i've got, upon saving the original, several documents ("regions") with the SAME AI file in it, true..
    let's take ID as the final layout program for each "region" and positioning each region in a rectangle frame.
    Now here's my problem,;
    if this was only vector art,( Roads, Area fills, landmarks etc and NO text) there's no problem at all.
    But I've got several text which has to be in Region A, partial in Region B but Not C... and text that has to be in all of them.
    So if I save the file for region A it's not usable for Region B,C etc.
    In the case of an Atlas of the complete citymap every "page" (region) has got it's one specific layers to be on and off.
    Upon save of the original (set to be oké for page 1) , it is also updated in page 2,3,4 etc but WRONG.
    ( one document for each page, and then again one Export for each page to be printed)
    The use of linked EPS (PDF, etc) is in my opnion a better solution because of there specific output. (only for 1 page ("region")
    Doing this from whitin the original, layers on/off and export just that specific portion for layout/print.
    Or am I missing something?
    Besides that when I place(Link) the original AI file in ID it's bounding box is the size of the original document and not the size of the piece I only want to see...
    So don't get me wrong again, don't be offended, I only want to get things completely clear for future use of AI and a consistend workflow!
    that's why there is a Forum, asking, explaining and helping each other to solve problems, get ideas...etc
    So, master, is grasshopper seeing things completely wrong?

  • Airport Express vs. Airport Extreme... which would work best for me?

    Okay, I've owned a few Apple products over the years, but have recently replaced my laptop with a Macbook Pro.  So, everything in our house that uses a wireless connection is made by Apple.  The only reason I say that is because my wireless router is a few years old, and I seem to be having some issues with it.  So, I am probably going to replace it.  I also mentioned the all-apple status because it seems to be logical that I would buy an Apple router to go along with all of this.  If that's a bad assumption, please let me know.
    Here is what accesses our network each day.  One Macbook Pro, an iMac, two iPads, 3 iPhones, an Apple TV (about to buy another one for upstairs), and a wireless printer.  I occasionally use my XBox to play online, but not heavily.  We also work with teenagers at our church, and often have a group of them over at our house....and they all use the network with their phones.  I don't want to just buy the more expensive router so that they can use wifi... I just mentioned it to see if that would bring out any key differences in the two.  Does one support more users than the other? 
    Which one would you guys suggest?  I obviously like the price tag of the Express, but do not want to be disappointed...  Thanks!

    Compare the products here:
    http://www.apple.com/compare-wifi-models/
    If the primary use of the AirPort will be to provide a wireless connection to devices, then it would probably be OK.
    But, you cannot connect a USB hard drive to the AirPort Express, and it does not have the better wireless antennas that are present in the AirPort Extreme.
    If you need to connect Ethernet devices to the AirPort, the AirPort Extreme uses Gigabit Ethernet ports.....10 times faster than the ports on the Express. No contest there.
    The AirPort Extreme will also provide a much faster 802.11ac wireless signal, but you will need to have an 802.11ac device like the new MacBook Air, MacBook Pro or iMac to realize the benefit. Other wireless devices will connect at the speeds at which they are capable.
    Either the Express or the Extreme will support up to 50 wireless connections.
    For me, the Extreme is a "no brainer" in terms of performance and future compatibility with newer wireless devices coming down the pike.....but if you don't need to connect a hard drive to the AirPort, you may disagree.

  • Which camcorder works best with iDVD/iMovie?

    So I'm buying a new camcorder. Which camcorder is the easiest to use with iDVD and iMovie? For now I just want to view and produce a DVD.
    I had a JVC Everio and returned it. Converting MPEG-2 to DV I guess can be done but seems like a lot of work. My first attempt with Streamclip asked me to buy the MPEG-2 module.
    I'm now looking at a Sony HDR-SR1. Thought the AVCHD would be MPEG-4 compatible and work with iMovie/iDVD but not sure. It will record in both AVCHD and MPEG-2 though.
    Any suggestions or ideas? I could really use the help.

    Welcome Michael Snell
    I use sony camcorders (minidv plus i.Link) successfully with iLife '06 and FCP HD. The ones to avoid are those that record to DVD directly or to an internal hard drive. Make sure your camera has digital pass thru which will also allow you to connect most analog sources as well should you need to like a VCR or another camera for import into iMovie via firewire.
    Canon also works well but represents my second choice of minidv cameras.
    JVC is in the same situation and would represent a third choice IMO.
    The good news is that almost any minidv camcorder will work on a mac that uses fw provided it records to mini dv tape and has a firewire or i.Link connector/s.

  • Which camcorder works best with mac computer

    I am looking to purchase a camcorder for my teen ager.  She is interested in making short movies and using imovie and the mac computer to edit them, etc.  Which canon  camcorder would be best?

    elvis25,
    I will be more than happy to recommend a model to you.  What price range are you looking to stay in?
    If this is a time sensitive-matter, additional support options are available at Contact Us.
    Did this answer your question? Please click the Accept as Solution button so that others may find the answer as well.

  • Which TABLET works best with Photosop 12

    I use my laptop for my photoshop needs but it is too heavy and cumbersome .......anyone know which  T
    ABLET is compatible and fast enough for Photoshop 12?

    The microsoft surface pro 3 should work.

  • Imovie or final cut express, which one works best?

    I am sick and tired of all the bugs in imovie. And I feel bad for everyone who are going out of their minds with soooooooo many problems with imove. I'm ready to buy final cut express, but does any one know if final cut express will run alot smoother and more relieable than imovie?
    Thanks, ED

    Hi M
    I also use iMovie (pref v6) and FinalCut Express (3.5.1) and FCP (5.x.?).
    FinalCut Express and Pro are rather same in work flow. iMovie is mentally
    somthing completely different.
    You need to be a very organized person to get the best of FCE eg. numbering all
    Your tapes (tape unique numbering), preparing a structure from beginning etc.
    BUT: The freedom of about 99 video and audio tracks. Resizing a video track
    above another (pic-in-pic), rotating a slightly off horizon eg 2 deg, color-
    correction (much better than in iMovie), Green/blue screen and so much more
    that needs plug-ins to iMovie (with a cost) as standard.
    Can give Your creativity a real spinn.
    Yours happy with both worlds: Bengt W

  • 16:9 or 4:3    Which Format Works Best, for most hardware?

    Hi There,
    I am having a problem with knowing what format to burn a DVD in within iDVD..
    I burned a DVD slide show made with iPhoto, and when I put it to DVD, and I play it back on my external player all the people in the video seem to be wider than they should be.
    It's a regular DVD player, not HD or Blu-Ray..
    I was wondering what the best format is for just a regular DVD player/playback output, so everyone looks like they should. (Not stretched, or squished)
    What's the rule of thumb for the best compatibility across the board for producing DVDs that look their best across different DVD players?
    Thanks for any help, and Happy New Year,
    Eric

    4:3 aspect ratio normally is a fairly safe bet. However standard television sets are quickly being replaced with wide screens at a record number.
    The problem in 16:9 is that the WS flag that tells your standard Dvd player to go wide screen isn't always picked up by the device. And that's when we run into issues.
    But to answer your question fully you really need to understand not only aspect ratios but also resolutions. This link usually helps answer a few concerns in regards to Preparing images for iDVD slideshows:
    http://docs.info.apple.com/article.html?path=iDVD/7.0/en/6675.html
    Hope the above helps but if not just come on back.
    Message was edited by: SDMacuser

  • Which stylus works best with ipad 3?

    Want to purchase a good stylus for use with the IPAD 3.  Any suggestions?

    I'll be sending the SB6141 back to Amazon and looking for a different model.
    The AC routers.. Extreme or TC both have problems with the SB6121 and 6141.. just search for either of those model numbers and there are lots of posts about the issue.
    There are some solutions but none work 100%.. some airports work fine.. some fail.. of those that fail some can be fixed using a crossover cable or a switch between the modem and the airport.. but not all.
    Sometimes it is easier to go with a standard modem router and use the Airport in bridge. It gives you most of its functionality in bridge just fine.. and only misses out on BTMM working properly because apple refuse to fix their upnp issues.

Maybe you are looking for