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?
Also using a for/while that calls every callback that may not even be neededWhy would you even do that? Do you even know what a callback is?
Why would you even do that?any better idea
Do you even know what a callback is?using ``callback'' in that was a mistake, but I think it was very clear what I meant
And why are you microoptimizing before profiling?It is not microoptimisation, it is very clear that it is going to be slower that way
I bet you're going to use dynamic linking, killing any LTO you might have gotten.You do not know me
any better idea
but I think it was very clear what I meant
It is not microoptimisation, it is very clear that it is going to be slower that way
Yes. Use callbacks properly.explain
pretndingwhat does this even mean?
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.no idea how it would work
Callbacks are much more maintainable and scalableFuck off, Javashit loving fagstorm. Die in a fire.
Even if you get the compiler to emit an O(1) switch (good luck with that)What? Ever heard of branch tables?
[](){}
Provide a testcase -- a small snippet of code that is running slower than you'd like.
while (SDL_WaitEvent (&e))
for (size_t i = 0; i < events_p; i++)
events[i].fun (e, events[i].arg);
Callbacks are much more maintainable and scalable [than big switch statements]Really?
You are passing the struct by value to your callbacks. Why does this run slower than you'd expect?it runs slower even if I use a pointer
Why does this run slower than you'd expect?because turds
char *temp = (char*)realloc(source->data, source->length + bs);*vomits*
char *temp = realloc(vec->chars, vec->length * vec->size);