Why iterator

Why do I need an Iterator (vector.iterator() or arraylist.iterator()) to iterate a collection object though I have all required methods to access the collection object.

aksarben wrote:
My point was that you can use for loops without iterators.Okay. I was more aiming at the OP and other newbies who might be reading. There used to be a lot of "for loop vs. iterator" questions here, as if it were either/or, when the real either or is get() vs. iterator. I assume the confusion came from the fact the one of the standard idioms for using an iterator used a while loop, while get() typically used a for loop.
The following are all equivalent:
// "old" idiom that newbies were most familiar with
List list = ...;
Iterator it = list.iterator();
while (it.hasNext()) {
  X x = (X)it.next();
  // do stuff
// "old" idiom that most experienced developers I've worked with used
List list = ...;
for (Iterator it = list.iterator(); it.hasNext();) {
  X x = (X)it.next();
  // do stuff
// "new" idiom which is just syntactic sugar for the above
List<X> list = ...;
for (X x : list) {
  // do stuff
}And the wrong ways to iterate, which are equivalent to each other, but not equivalent to the above are:
List<X> list = ...;
// wrong idiom which newbies are familiar with
for (int i = 0; i < list.length(); i++) {
  X x = list.get(i);
  // do stuff
// wrong idiom which is equivalent to the above, but not common
int i = 0;
while (i < list.length()) {
  X x = list.get(i);
  // do stuff
}

Similar Messages

  • Why iterator is interface

    hi,
    why iterator is an interface and not a class.
    Thanks,

    Iterator is set up as an interface so that you may define iterators of your own for your own classes. Let's assume you create some class MyClass. If this class does not directly extend a class that has a method to return an iterator you would need to define one yourself. So you could create a class MyClassIterator that implements Iterator. Then in MyClass you can add a method as follows:
    public class MyClassIterator implements Iterator
    MyClass obj = null;
    public MyClassIterator(MyClass obj) { this.obj = obj; }
    public boolean hasNext() {...}
    public Object next() { ... }
    public void remove() { ... }
    public MyClass
    public Iterator iterator()
    return new MyClassIterator(this);
    }

  • Iterator refresh after commit

    Hi,
    I have three tabs in my page , and in each tab , i have separate taskflows.
    The first tab taskflow contains a jsff which has lets say master table iterator i.e departments iterator.
    In the second tab, i have a table based on read only query, but when i click on add button, i will be inserting in to detail VO (employee VO) and using postChanges() .
    so that read-only query based table gets the new data.
    now when i click on save button and commit , the iterators in taskflows of tab1, tab2 are pointing to first record rather than the current record.
    1) even i tried with having an action for the 'save' button and navigating to method activity which sets the iterator to current row.
    When i am returning back to taskflow,i am still seeing the iterator pointing to first record rather than the current record i intend to see.
    could anybody tell me why iterator is pointing to first row after commit()
    i don't have 'refresh' -- if needed for taskflows. its default.
    for transactions, datacontrols, its default for my taskflows.

    I generally retain the previously selected row using the following code in my VOImpl after every executeQuery().
    public void executeQuery()
    // current row key if any
    Key currentRowKey = null;
    Row currentRow = getCurrentRow();
    if ( currentRow != null )
    // get current row key
    currentRowKey = getCurrentRow().getKey();
    // super call
    super.executeQuery();
    if ( currentRowKey != null )
    // set current row now using previously stored key
    Row[] rows = findByKey( currentRowKey, 1 );
    if ( rows != null && rows.length == 1 )
    setCurrentRow( rows[0]);
    }

  • Why do I need to define these in std for my random access iterator???

    Hi guys,
    I have written my own iterator class, to support 1-d slices of 2-d matrices, 2-d slices of 3-d matrices, etc.
    At first I wrote the class as a bidirectional iterator, but then I needed to extend it to random access so that I could pass these iterators to std::sort etc. No problem, I thought, I just needed to add friend operators for "iterator-iterator" and "iterator+/-distance".
    So, I did that and tested the code with VS6 and various versions of g++, with no problems. Isn't STL great!
    But I had endless problems with Studio 10. It kept griping that various mostly-internal-looking template functions were not defined. The only way I could get it to work was to define these:
    #if (defined __SUNPRO_CC) && (__SUNPRO_CC <= 0x570)
    namespace std
         template<typename T>          // Sigh
         typename matrixit<T>::
         difference_type distance(const matrixit<T>& a, const matrixit<T>& b) {
              return b-a;
         template<typename T>           // WTF?
         T* __value_type(const matrixit<T>&) {
              return static_cast<T*>(0);
         template<typename T>           // WTF?
         typename matrixit<T>::
         difference_type* __distance_type(const matrixit<T>&) {
              return static_cast<typename matrixit<T>::difference_type*>(0);
         template<typename T>           // WTF?
         typename matrixit<T>::
         iterator_category __iterator_category(const matrixit<T>&) {
              return typename matrixit<T>::iterator_category();
    #endif
    Why do I have to do this, or am I missing something in my iterator class (eg, typedefs), or do I need to derive it from something? Here is what it looks like:
    template<typename T>
    class matrixit
    public:
         typedef T&                         reference;
         typedef T*                         pointer;
         typedef T                         value_type;
         typedef size_t                    size_type;
         typedef ptrdiff_t               difference_type;
         typedef std::random_access_iterator_tag iterator_category;
    Ta, Simon.

    Come on, it is not that hard to work around the limitations of Cstd. For what you show here, you can use:
    namespace std {
    template <class Iterator> struct iterator_traits
    typedef typename Iterator::value_type value_type;
    typedef typename Iterator::difference_type difference_type;
    typedef typename Iterator::pointer pointer;
    typedef typename Iterator::reference reference;
    typedef typename Iterator::iterator_category iterator_category;
    template <class T> struct iterator_traits<T*>
    typedef T value_type;
    typedef ptrdiff_t difference_type;
    typedef T* pointer;
    typedef T& reference;
    typedef random_access_iterator_tag iterator_category;
    template <class T> struct iterator_traits<const T*>
    typedef T value_type;
    typedef ptrdiff_t difference_type;
    typedef const T* pointer;
    typedef const T& reference;
    typedef random_access_iterator_tag iterator_category;
    template <class ForwardIterator>
    inline ptrdiff_t
    distance (ForwardIterator first, ForwardIterator last)
    ptrdiff_t n = 0;
    __distance(first, last, n,
    iterator_traits<ForwardIterator>::iterator_category());
    return n;
    template <class InputIterator, class T>
    inline typename iterator_traits<InputIterator>::difference_type
    count (InputIterator first, InputIterator last, const T& value)
    typename iterator_traits<InputIterator>::difference_type result;
    count(first,last,value,result);
    return result;
    template <class InputIterator, class Predicate>
    inline typename iterator_traits<InputIterator>::difference_type
    count_if (InputIterator first, InputIterator last, Predicate pred)
    typename iterator_traits<InputIterator>::difference_type result;
    count_if(first,last,pred,result);
    return result;
    template < class T >
    inline typename T::value_type*
    __value_type (const T&)
    { return (typename T::value_type*)(0); }
    template < class T >
    inline typename T::difference_type*
    __distance_type(const T&)
    { return (typename T::difference_type*)(0); }
    template < class T >
    inline typename T::iterator_category
    __iterator_category (const T&)
    typename T::iterator_category tmp;
    return tmp;
    } // namespace std
    For the missing constructor of vector with iterators, you can simply use std::copy with a back_insert_iterator.
    The hardest thing to work around is probably the missing conversion between std::pair of various types (for instance with various constness when you use std::map), but it can still be handled by always specifying the type of the pair instead of relying on std::make_pair.
    And if there is a thing you really don't know how to work around, you can always ask here...

  • ListIterator is sbuinterface of Iterator, why do I have to import  both?

    ListIterator is sbuinterface of Iterator, why do I have to import both?

    "Import" simply tells the compiler what package a class or interface is in. It's possible for a class or interface in one package to extend something in a different package, in fact it happens quite often. For example, class org.me.visual.Finger might extend org.me.utils.BodyPart.
    It doesn't seem obvious to me that if I tell the compiler that "Finger" means "org.me.visual.Finger", it would automatically conclude that "BodyPart" means "org.me.utils.BodyPart". Why should this happen? And in fact it doesn't happen, which seems quite reasonable to me.
    PC&#178;

  • Iteration a signed integer and not an unsigned integer, why?

    i was just wondering if there is a reason for keeping the iteration variable/indicator of a loop a signed 32 bit integer.
    it is never going to take a negative value.. then why signed; unsigned could have served the purpose
    Message Edited by Ujjval Shah on 07-08-2009 09:21 AM
    Solved!
    Go to Solution.

    Remember that array sizes are limited to I32 (the "size" input to initialize array is I32, the output of Array size is I32, etc), so running a FOR loop more than 2^21 times is not even possible (N is also I32).
    While loops can of course run forever, so if you need to increment a counter more than 2^31 times, you can use a shift register with U64, for example. However, don't even try to autoindex an output tunnel of such a loop, you're almost guaranteed to run out of memory before you reach the limits of I32.
    Using array indices as I32 has several advantages. For example sometimes you need an invalid index (Integers don't have NaN!), so having a negative number is very useful. For example if you use "search array" and no match is found, the output is -1.
    I suspect in the very long run these things will change. In another decade, all OSs will be 64bit or more and RAM will be mesured in TB. LabVIEW will need to evolve too to keep up. 
    LabVIEW Champion . Do more with less code and in less time .

  • Why is loop iterator signed and not unsigned?

    Why is the data type of loop iterator a signed integer rather than an unsigned integer?  

    I32 is much more universal, and is for example used for array indices, array sizes, etc. The iteration terminal is most often connected to one of those functions. Your diagram would have the measles, with coercion dots all over without I32 on the iterator.
    If you need to keep count with e.g. U32 or U64, you can make your own using a shift register and +1 function.
    (There are ideas to make the representation changeable according to your needs. See also my comment here)
    LabVIEW Champion . Do more with less code and in less time .

  • Why in case of parent child relation iterator fetching one duplicate record

    Hi,
    JDev Ver : 11.1.1.2.0
    Technology : JPA/TopLik Service Facade Data Control (Without using BC4J)
    I have created JPA/TopLink service facade from DB Tables and on facades I have crated DataControl which I have draged and droped on my screen to create input text, table etc.
    In my application, I have many tables having one to many relationships. (Primarykey foreign key).
    When I add more then one child columns (foreign key columns) for any one parent column (primary key column), in db its getting inserted properly but in iterator after refreshing also it showing one duplicate entry instead of actual entry.
    e.g.
    For one Account Id 1234 (primary key) , I am adding 3 account holders name (abc, xyz, pqr) in this case in db its inserting proper 3 entries but in iterator its showing
    1234 abc
    1234 xyz
    1234 abc
    so instead of pqr its again showing abc.
    To select account holders name I have used selectManyShuttle components.
    I have also tried tried dciter.refresh(DCIteratorBinding.RANGESIZE_UNLIMITED); to refresh iterator.
    This is generic problem on most of the screen in my application where parent child relation comes.
    regards,
    devang

    Hi,
    Thanks for your reply. I just emailed the screen shot to your email . Please verify and let me know your comment.
    Regards,
    Kiran Konjeti

  • Why is the ArrayList.iterator() so slow

    Take a look at the code below. I believe its correct. If so, I can get 3x the performance doing a classic for loop when iterating the list.
    public static void main(String[] args)
              List<Double> theList = new ArrayList<Double>(LIST_LENGTH);
              //Only run last test with Linked List
              //List<Integer> theList = new LinkedList<Integer>();
              Random rand = new Random();
              System.out.print("Populating list with " + LIST_LENGTH + " items.");
              for (int i = 0; i < LIST_LENGTH; i++)
                   theList.add(rand.nextDouble());
              System.out.println("Done!");
              //new Zebra(theList);
              System.out.println("Classic For Loop");
              double t1 = 0;
              long start = System.currentTimeMillis();
              for (int i = 0; i < LIST_LENGTH; i++)
                   t1 += theList.get(i);
              long stop = System.currentTimeMillis();
              System.out.println("Total1: "  + t1 + " Time: "+  + (stop - start));
              System.out.println("New For Each Loop");
              double t2 = 0;
              long start2 = System.currentTimeMillis();
              for (double f : theList)
                   t2 += f;
              long stop2 = System.currentTimeMillis();
              System.out.println("Total2: " + t2 + " Time: "+ (stop2 - start2));
              System.out.println("Iterator based loop");
              double t3 = 0;
              long start3 = System.currentTimeMillis();
              for (Iterator<Double> it = theList.listIterator(); it.hasNext();)
                   t3 += it.next();
              long stop3 = System.currentTimeMillis();
              System.out.println("Total3: " + t3 + " Time: "+ (stop3 - start3));
         }Here is a print screen of a run. These results are typical. It does not matter which order I run the test.
    Populating list with 20000001 items.Done!
    Classic For Loop
    Total1: 9999145.376459487 Time: 375
    New For Each Loop
    Total2: 9999145.376459487 Time: 1079
    Iterator based loop
    Total3: 9999145.376459487 Time: 1063Anyone running this will need to get their -Xmx parameter up fairly high.

    I expect that's the case. There are times though, like in this sample, when there is no chance the list will be modified by another thread. I guess this is just a lesson "knowing your language." I discovered this when testing a multiple thread sumation. For the curious I have posted the rest of the class below. It would be interesting to see the results on an Core i7 processor.
    One thing this does show is that "multi-threaded" is not necessairly the best way to do things. I have to have a very large collection before the "Divide and conquor" approach shows any benefit. Test relatively similar performance until I get to a collection of 2,000,000 or more objects.
    This test also shows how inaccurate even dobule percision floating point math can be. If I change the items in the lists to ints the numbers will all match. There cases when using doubles will match too. Ex: Instead of using random numbers I just use "1". In this case using floats will be different but using doubles will give the right answer.
    import java.util.ArrayList;
    import java.util.HashSet;
    import java.util.Iterator;
    import java.util.List;
    import java.util.Random;
    import java.util.Set;
    public class Zebra
         private final Set<xThread> runningThreads = new HashSet<xThread>();
         private float total = 0;
         private static final int LIST_LENGTH = 50000000;
         private static final int NUM_THREADS = Runtime.getRuntime().availableProcessors();
         public Zebra(final List<Double> theList)
              final int LIST_LENGTH = theList.size();
              final int paddingNeeded = (LIST_LENGTH % NUM_THREADS) > 0 ?
                                           NUM_THREADS - (LIST_LENGTH % NUM_THREADS) : 0;
              final int effectiveLength = LIST_LENGTH + paddingNeeded;
              System.out.println("Adding padding " + paddingNeeded);
              for (int i = 0; i < paddingNeeded; i++)
                   theList.add(0d);
              // Split job into threads
              System.out.println("Divide and Conquor (note this test is counting overhead of setting up threads)");
              long start = System.currentTimeMillis();
              synchronized (this)
                   for (int i = 0; i < NUM_THREADS; i++)
                        xThread x = new Zebra.xThread(theList,
                                                             (effectiveLength / NUM_THREADS) * i,
                                                             (effectiveLength / NUM_THREADS) * (i + 1), this);
                        runningThreads.add(x);
                        x.start();
                   while (runningThreads.size() > 0)
                        try
                             wait();
                        catch (InterruptedException e)
                             e.printStackTrace();
              if (paddingNeeded > 0)
                   for (int i = 0; i < paddingNeeded; i++)
                        theList.remove(theList.size() - 1);
              long stop = System.currentTimeMillis();
              System.out.println("Total: " + total + " Time: " + (stop - start));
         private void threadDone(xThread x)
              synchronized (this)
                   runningThreads.remove(x);
                   notifyAll();
                   total += x.getTotal();
         private class xThread extends Thread
              private final List<Double> list;
              private final int startIndex, endIndex;
              private final Zebra backRef;
              private double total = 0;
              public xThread(List<Double> list, int startIndex, int endIndex,
                        Zebra backRef)
                   this.list = list;
                   this.startIndex = startIndex;
                   this.endIndex = endIndex;
                   this.backRef = backRef;
              public double getTotal()
                   return total;
              public void run()
                   for (int i = startIndex; i < endIndex; i++)
                        total += list.get(i);
                   backRef.threadDone(this);
         public static void main(String[] args)
              List<Double> theList = new ArrayList<Double>(LIST_LENGTH);
              //Only run last test with Linked List
              //List<Integer> theList = new LinkedList<Integer>();
              Random rand = new Random();
              System.out.print("Populating list with " + LIST_LENGTH + " items.");
              for (int i = 0; i < LIST_LENGTH; i++)
                   theList.add(rand.nextDouble());
              System.out.println("Done!");
              new Zebra(theList);
              System.out.println("Classic For Loop");
              double t1 = 0;
              long start = System.currentTimeMillis();
              for (int i = 0; i < LIST_LENGTH; i++)
                   t1 += theList.get(i);
              long stop = System.currentTimeMillis();
              System.out.println("Total1: "  + t1 + " Time: "+  + (stop - start));
              System.out.println("New For Each Loop");
              double t2 = 0;
              long start2 = System.currentTimeMillis();
              for (double f : theList)
                   t2 += f;
              long stop2 = System.currentTimeMillis();
              System.out.println("Total2: " + t2 + " Time: "+ (stop2 - start2));
              System.out.println("Iterator based loop");
              double t3 = 0;
              long start3 = System.currentTimeMillis();
              for (Iterator<Double> it = theList.listIterator(); it.hasNext();)
                   t3 += it.next();
              long stop3 = System.currentTimeMillis();
              System.out.println("Total3: " + t3 + " Time: "+ (stop3 - start3));
    }Results:
    Populating list with 50000000 items.Done!
    Adding padding 0
    Divide and Conquor (note this test is counting overhead of setting up threads)
    Total: 2.499794E7 Time: 656
    Classic For Loop
    Total1: 2.499794097321981E7 Time: 954
    New For Each Loop
    Total2: 2.499794097321981E7 Time: 3080
    Iterator based loop
    Total3: 2.499794097321981E7 Time: 2658

  • Java 1.4.2: Iterator cannot be resolved...  Why??????

    Hello fellow java developers!
    I'm using java 1.4.2 - a requirement for this project.
    The issue that I'm running into is when I declare an Iterator for use in the program.
    The code is simple, but fails miserably.
    Iterator itRows = hsSheet.rowIterator(); // this is a function from apache POI that is supposed to return an iterator
    The issue is clear enough. "Iterator cannot be resolved to a type". But seems strange. If I try to declare the iterator type like this:
    Iterator<HSSFRow> itRows = hsSheet.rowIterator(); // this tells me that "paramaterized types are only available if the source is 5.0 or above - 1.4.2 is required.
    Any ideas???

    An SSCCE may be hard to produce if the problem is due to the Apache library or his use of the library. :(
    Is there some ambiguity as to what iterator you are using due to another library containing an Iterator class being added in your imports? Have you tried specifying the full class name?
    java.util.Iterator itRows = hsSheet.rowIterator();Also, when posting code here, please use code tags so that your code will retain its formatting and thus will be readable -- after all, your goal is to get as many people to read your post and understand your code as possible, right?
    To do this, highlight your pasted code (please be sure that it is already formatted when you paste it into the forum; the code tags don't magically format unformatted code) and then press the code button, and your code will have tags.
    Another way to do this is to manually place the tags into your code by placing the tag [cod&#101;] above your pasted code and the tag [cod&#101;] below your pasted code like so:
    [cod&#101;]
      // your code goes here
      // notice how the top and bottom tags are different
    [/cod&#101;]Luck!

  • Reasons why to use Iterator for List rather than for loop ?

    when i use the iterator and for loop for traversing through the list. it takes the same time for iterator and also for for loop. even if there is a change it is a minor millisecond difference.
    what is the actual difference and what is happening behind the traversing list through iterator
    if we are using we are importing extra classes ...if we are using for loop there is no need to import any classes

    If you have an array-backed collection, like an ArrayList, then the difference between using an iterator and get() will be negligible.
    However, if you have a linked list, using get() is O(n^2) whereas iterator is O(n).
    So with an iterator, regardless of what your underlying data structure, a list of 100,000 elements takes 1,000 times as long to iterate over as a list with 100 elements. But using get() on a LinkedList, that same 100,000 element list will take 1,000,000 times as long as the 100 item list.
    There's no real benefit to ever using get()
    Side note: I've been comparing iterators to get(), not iterators to for loops. This is because whether it's a for or a while has nothing to do with whether you use an iterator or get(). The way I use iterators is for (Iterator iter = list.iterator(); iter.hasNext(); ) {
        Foo foo = (Foo)iter.next();
    }

  • What is Iterator? and Why is it used?

    Hi,
    I am newbie to BSP and ABAP, and came across iterator while going through some topic.
    I used iteration process to display the values in the view in a table,
    Is it some way similiar to it with different approach?

    Hi,
    Iterator is to design each and everycell in your table in different format and to design your table that and end your can change what ever he wants in the table and saves the data changed.
    You can disign your tableview like it has a dropdown in one column, input field in one column and image in on column and link in one column like that.
    Check the below links..
    http://help.sap.com/saphelp_nw04/helpdata/en/28/4bae407e69bc4ee10000000a1550b0/frameset.htm
    /people/brian.mckellar/blog/2003/10/31/bsp-programming-htmlb-tableview-iterator
    http://help.sap.com/saphelp_me21sp2/helpdata/en/f7/faec246c2d184191bea02f703fc830/frameset.htm
    /people/thomas.jung3/blog/2004/09/15/bsp-150-a-developer146s-journal-part-xi--table-view-iterators
    Thanks,
    Sreekanth
    <i>*-- Please reward if it helps u</i>

  • Why is row currency not reset back in my iterator

    Dear All,
    Use case:
    I am displaying my view object in an input form with navigation controls.
    In a method I need to do some processing on some rows in an iterator and then after processing I need to return the row currency to the first row.
    Please consider this code. I am calling this code in a button action listener. Upon clicking this button, I just wanted to process something on the rows of my iterator and after processing I wanted reset my form into the first row.
    DCBindingContainer bindings =
      (DCBindingContainer) BindingContext.getCurrent().getCurrentBindingsEntry();
    DCIteratorBinding iter =
      bindings.findIteratorBinding("MyIterator");
    RowSetIterator rsi = iter.getRowSetIterator();
    //Get the first row
    Row firstRow = rsi.first();
    String firstRowKeyString = firstRow.getKey().toStringFormat(true);
    More Processing
    //Return the row currency to the first
    iter.setCurrentRowWithKey(keyString);
    iter.refreshIfNeeded();
    //PPR the formNot sure but, I cannot see my input form to return to the first row even if I PPR the form.
    Anything missing? This is an ADFBC business interface.
    Any thoughts?
    JDev 11.1.1.6
    Edited by: Neliel on Aug 15, 2012 2:22 AM

    Filedropper is firewalled over here so apologies for not giving it a go but have you tried to do this, navigate to the first row in the rowsetiterator just before you ppr the page. Example:
    public void handleCancel(ActionEvent actionEvent)
         FacesContext fctx = FacesContext.getCurrentInstance();
         DCBindingContainer bindings =
           (DCBindingContainer) BindingContext.getCurrent().getCurrentBindingsEntry();
         DCIteratorBinding iter =
           bindings.findIteratorBinding("AllDepartmentsIterator");
         //clear the bindings
         Row rw = iter.getCurrentRow();
         OperationBinding getRowStatusBinding =
           bindings.getOperationBinding("getRowStatus");
         String rwStatus = (String) getRowStatusBinding.execute();
         if ("NEW".equalsIgnoreCase(rwStatus))
           iter.removeCurrentRow();
           iter.refreshIfNeeded(); //Remove this, you already do it after the if
         else
           rw.refresh(Row.REFRESH_UNDO_CHANGES);
         //set the row currency to the first row
         //iter.setCurrentRowWithKey(keyString);
         iter.refreshIfNeeded();
         RowSetIterator rsi = iter.getRowSetIterator();
         //retrieve the first row
         Row firstRow = rsi.first();
         //String keyString = firstRow.getKey().toStringFormat(true);
         //PPR the form
         UIComponent uiCOmponent = (UIComponent) actionEvent.getSource();
         while (true)
           if (uiCOmponent instanceof RichPanelFormLayout)
              break;
           else
              uiCOmponent = uiCOmponent.getParent();
         AdfFacesContext.getCurrentInstance().addPartialTarget(uiCOmponent);
    }

  • Why does WFM_DB_Transfer generate an error 10803 after functioning well for a few iterations?

    I am outputing a waveform via the WFM_DB_Transfer function, and it functions fine for about the first fifty or so buffers. However afterwards it generates the error 10803. This happened when I had the oldDataStop set to 1 in the WFM_DB_Config. My situation is that I am trying to simulatenously acquire data while trying to send data so I am using double buffered waveform generation on an AT-AO-10 board with double buffered data acquisition on a PCI-6071E board which both are synchronized through the RTSI bus using an external update clock. The thing is everything works except after about 50 or so iterations of buffers later the 10803 error pops up. Sometimes the iterations
    last up to 300 before coughing up the error 10803. I am using NI-DAQ 6.9.1.

    Take a look at this Knowledgebase entry. It may be related to your problem.
    http://digital.natinst.com/public.nsf/fca7838c4500dc10862567a100753500/a1973fc28be27737862562210059bc32?OpenDocument
    Hope this helps.
    Regards,
    Erin

  • Why do my loops slow down after many iterations

    My Vi seems to freeze up or slow down after several iterations of the loop. This is an Analog Input Capture VI.
    Attachments:
    Final_Main_VI_with_working_amp.vi ‏456 KB

    First of all, thank you for your contribution. You are right to say that I have no need in changing the AI Config every time that the loop runs. But as this is supposed to be a soft-scope, I need to be able to update the parameters associated with AI Start while the loop is running (e.g. trigger level).
    I have tried to move the AI Config subVI out of both loops but the error as a result is: "No transfer in progress for the specified source."
    I also need a sampling rate of exactly 96kHz. I realize that the laptop clock cannot attain this value. Do you know how I could get exactly 96kHz.
    Attachments:
    Final_Main_VI_with_working_amp.vi ‏498 KB

Maybe you are looking for