www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Out of order execution

reply Joerg Joergonson <JJoergonson gmail.com> writes:
Suppose I have a loop where I execute two functions:

for(...)
{
    if (x) Do1(x);
    if (y) Do2(y);
}

The problem is, I really always want to execute all the Do2's 
first then the Do1's. As is, we could get any order of calls.

Suppose I can't run the loop twice for performance reasons(there 
is other stuff in it) and I don't want to store the state and 
call info then sort them out afterwards.

Is there an efficient lazy way to make this happen?
Jun 15 2016
next sibling parent Andrea Fontana <nospam example.com> writes:
On Thursday, 16 June 2016 at 01:57:19 UTC, Joerg Joergonson wrote:
 Suppose I have a loop where I execute two functions:

 for(...)
 {
    if (x) Do1(x);
    if (y) Do2(y);
 }

 The problem is, I really always want to execute all the Do2's 
 first then the Do1's. As is, we could get any order of calls.

 Suppose I can't run the loop twice for performance 
 reasons(there is other stuff in it) and I don't want to store 
 the state and call info then sort them out afterwards.

 Is there an efficient lazy way to make this happen?
Something like: https://dpaste.dzfl.pl/79b77c934825 ?
Jun 16 2016
prev sibling parent Rene Zwanenburg <renezwanenburg gmail.com> writes:
On Thursday, 16 June 2016 at 01:57:19 UTC, Joerg Joergonson wrote:
 Is there an efficient lazy way to make this happen?
No, I don't see how that would work.
 Suppose I can't run the loop twice for performance 
 reasons(there is other stuff in it) and I don't want to store 
 the state and call info then sort them out afterwards.
Storing the state is your best bet. Based on your recent post about OpenGL I assume this is for the same project? If so, you can reuse the storage buffer between frames. Generally speaking it's the allocations that are slow, copying some state to a buffer shouldn't be expensive. Use separate buffers for the Do1 and Do2 calls so you don't have to sort.
Jun 16 2016