Subscribe to this thread
Home - General / All posts - Programing Mfd9: Rewind a sequence

6,356 post(s)
#27-Jul-19 18:54

I have two nested loops and the inner loop walks through a sequence.

How can I wind back the record pointer to the initial state for the next step in the outer loop?

Or should I GetValues() of the sequence again and again (which works)?


236 post(s)
#28-Jul-19 17:44

Which language you are using?

In C#, I would put a conditional return; statement inside the inner loop. This should end the anonymous inner loop function and jump back to the outer loop's iteration.


6,356 post(s)
#29-Jul-19 22:21

Talking of the Manifold API and a sequence rewind after the Do While sequence.Fetch () ... Loop in the inner loop. Without that the next revolution of the outer loop skips the inner loop as there is nothing to fetch. What works is a sequence_GetValues again and again in the outer loop. But isn't that too expensive?

VB.Net (or C#)


8,958 post(s)
#30-Jul-19 10:55

Can't you post some code here Klaus?

To me it is opaque.

I think: you want each iteration of the outer loop to be able to reuse a common Sequence (in Python we might say a generator object), but also able to reset its pointer arbitrarily (to change the next member) according to a test or condition (so far undisclosed).

I don't think a Sequence object can work that way. It is necessarily sequential. There is no a random-access pointer, the record address is not a simple offset, but involves a (thread-safe and highly parellel) Fetch/Next function or method. (Who knows how they do that efficiently. Linked lists is as far as I can get.) Records are unlikely to be stored linearly except in trivial (small) cases, and their order can in principle change at any time, so the pointer(s) must be defined and managed much lower down. There must be at least two levels of indirection (pointers to pointers).

There might be a better way to achieve what you want. Maybe you do not even need two loops.


8,775 post(s)
#30-Jul-19 12:47

Keep dong Sequence.GetValues(), it is usually plenty fast not to be the bottleneck. This returns a new ValueSet for each record, and if you want to keep a ValueSet for a particular record, you can, calling Fetch() / GetValues() on the sequence that produced your ValueSet will not invalidate it. The reason this all is pretty fast is that all data that gets allocated for each new record is managed and while there is some overhead for re-creating the same structure of returned fields over and over, the bulk of the work is in copying / wrapping / unwrapping the actual values which come from the table. In addition, if you don't keep any ValueSet's and just do: fetch record - call GetValues - process returned values - stop using returned values - fetch another record - call GetValues again - process new returned values - etc, which is by far the most frequent scenario, the costs of setting up a new ValueSet every time nearly disappear because objects are all short-lived and memory just gets reused. If you try keeping ValueSet's for past records, the picture starts changing, and at some point (it is hard to give specific numbers because they depend on the number of fields, their types, and plenty of other things, but we are likely talking about something like 5,000 ValueSet's or more before this even appears on the radar) the overhead from having many separate ValueSet's starts becoming noticeable, and then you should consider storing things in plain arrays of ints / strings / whatever.

A sequence cannot rewind, it can only go forward. If you want to rewind, you have to store previous values.

Manifold User Community Use Agreement Copyright (C) 2007-2019 Manifold Software Limited. All rights reserved.