Re: to be effcient or not to be efficient
"Toby Hudon" <[email protected]>
| Newsgroups | gmane.comp.multimedia.media-api |
|---|---|
| Message-ID | <[email protected]> |
----- Original Message ----- From: Tuukka Toivonen <[email protected]> Date: Thu, 8 Jan 2004 21:05:36 +0200 (EET) To: "The attempt to create a new, open standard codec API" <[email protected]> Subject: Re: [Media-api] to be effcient or not to be efficient > On Thu, 8 Jan 2004, Toby Hudon wrote: > > >> > .seek_frame = NULL; /* not implemented call */ > >> If the vtable is set up by the API library (as opposed to a specific > >> codec/filter) it might be nicer to set unimplemented functions to > >> some dummy functions which just return an error instead of NULL; otherwise > >Umm... but if you have a function that just returns "not supported", won't > >you have to check for that every time after you call to see if what you > > - If the pointer may be NULL, you must check for it _before_ calling a > function and then you need another check _after_ the function to check > the return value for possible other errors anyway. > Therefore, dummy non-NULL pointers are more efficient (faster). > Umm... if the pointer is NULL you won't call it so there's no point in checking the return value after, there isn't one. If the only way to know if a function is valid is a return value then you have to call it to get that value. That's obviously slower and pointless. > - You might not care about possible errors, and in that case no > checks are necessary at all if non-NULL pointers are guaranteed > (it's also safer: some buggy code might not check for NULL > pointers but just call directly a function that is usually > implemented anyway, with dummy pointers no harm is done, > but with NULL function pointer there would be a segfault). > Ummm you might not care about possible errors now, but I'm pretty sure that if you're going to use a function pointer system it'd be a pretty good idea to check if the pointer is null when you get the function anyway, whether you wind up calling it or not. If you're getting dummy functions substituted, then to find out if the filter you called really does what you want you have to go through and call every possible function with some test parameters and then check its value. What if you have some function that's critical your component get from someone else? You ask it for the function and get a valid poitner back. Do you have the right function? You don't know, so you have to call it with some "safe" parameters that either you know the result of or must be predefined for EVERY function on their side to make sure you have the correct function. Versus just comparing them to null that's pretty tedious. -- ___________________________________________________________ Sign-up for Ads Free at Mail.com http://promo.mail.com/adsfreejump.htm