Re: to be effcient or not to be efficient

Artem Baguinski <[email protected]>
Newsgroups gmane.comp.multimedia.media-api
Message-ID <[email protected]>
On Thu, Jan 08, 2004 at 11:36:25AM +0200, Tuukka Toivonen wrote:
> On Thu, 8 Jan 2004, Artem Baguinski wrote:
> 
> >static vtable_t my_vtable {
> >  .get_next_frame = get_next_frame; /* implemented call */
> >  .seek_ms = seek_ms;               /* another one */
> >  .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
> the caller has to always check whether a pointer is NULL before calling the
> function.

he doesn't have to.

before the playback application started to play the stream it selects
the components checks if the methods it's gonna use are implemented. 

it should be up to this application what to do if some functionality
isn't present: it may simply make the corresponding GUI elements
disappear, so these methods won't be accessed; or it may chose one of
several playback functions / objects [this application specific i mean]
which is optimized to the situation [and won't call the NULL pointers];
OR it can provide some USEFUL stubs. 

with your approach instead of checking the NULLness of pointer before
calling a method i have to check NOT_IMPLEMENTED error code after
calling it, which just makes it messier: if i can leave without this
call i'd rather provide an alternative playback function that doesnt
make the call then one large and messy universal playback. 

on the other hand if the missing call is essentual i'll simply tell my
user "sorry, i can't use this source, do you maybe wanna convert it to
something i can eat? say PNGs wrapped in Matryoshka or JPEGs in MOV...
thanks in advance."

> There might then be another function for checking whether a function is
> implemented (if a codec/filter wants to really know if a function is
> implemented or returning error for some other reason).

just having NULLs for not implemented allows to do that, adding more
functions just compliocates the matter without necessity.

> If the vtable is set up by codec, using NULLs for unimplemented calls might
> be better because that makes the codec simpler.

exactly. 

-- 
gr{oe|ee}t{en|ings}
artm
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.