Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Question about event handling

Name: Anonymous 2014-06-21 11:42

Let's say I use SDL (1.2 or 2.0) in my program to handle events, should I use callbacks or the good old giant switch statement?

Name: Anonymous 2014-06-21 12:10

Callbacks are much more maintainable and scalable. Is this really a question?

Name: Anonymous 2014-06-21 12:23

>>3
Also using a for/while that calls every callback that may not even be needed
Why would you even do that? Do you even know what a callback is?

And why are you microoptimizing before profiling? I bet you're going to use dynamic linking, killing any LTO you might have gotten.

Name: Anonymous 2014-06-21 13:18

>>5
any better idea

Yes. Use callbacks properly.

but I think it was very clear what I meant

Callbacks are real things used for event handling. Whatever you are pretnding to be thinking of probably isn't.

It is not microoptimisation, it is very clear that it is going to be slower that way

It is, and callbacks aren't even slower. Even if you get the compiler to emit an O(1) switch (good luck with that), it's O(n) in terms of events received. Using callbacks is O(n) in terms of events handled.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List