[sdiy] MIDI bytestream parser

Tom Wiltshire tom at electricdruid.net
Tue Nov 16 12:07:42 CET 2010


On 16 Nov 2010, at 10:51, Olivier Gillet wrote:
>> I'm not sure I get this. Ok, status bytes are unique, I get that. And there are only certain values possible, I get that. And we have a function to call for each type of message. So far so good.
>> But what's the point of the hash? A lookup map, you say? So it maps from status byte x to function y? Why not use an array, a switch statement, a long if/elseif, or any of the other possible constructions that would provide this mapping?
> 
> Switch statements are likely to generate heavier code, because some
> compilers are unable to optimize them properly as jump tables - and
> they end up being compiled as a bunch of comparison / jump. Given that
> this kind of code could very well be embedded on platforms with 2 or
> 4k of code memory with lousy compilers, this is a sane thing to do.

Ok, *now* I get it, thanks!
It's a workaround for crap compilers to ensure that they produce something that is a reasonable approximation to efficient code. Because although the point of higher level languages is the easy readability and useful structures like switch, if you actually use them you finish up with hideous bloatware that won't go in your chip, let alone run fast and do the job in hand? Am I close?!

Grrr...not convinced by C. If that's the kind of stuff you have to do to make things work, I'm going back to assembly language...

Thanks for explaning, Olivier
Tom




More information about the Synth-diy mailing list