see i m writing one avi demuxer library. In which i have exported multiple API to do different functionality. NOw when 1st time one aviopen() is called with i/p filename, i parse whole file & save some info in some structure which i have malloc. now when again any API is called for that file should use that structure's info & do some work.
i DO NOT wan开发者_如何学Got to expose those structure to library user. even i DO NOT want no give him the pointer of that structure. In that case how can i keep the track of that structure???
i also want to give multiple file support in my library so if any application wants to open more than one file at a time then he can do that.
so here how can i maintain handle of each opened file for allocated structure?
An opaque pointer is the usual way to implement this.
If you don't want to pass a pointer at all for some reason, you could keep a global ("private") array/hash of your structures, and give your users an index in that global container (could be a plain int). That's much more work (and much more failure-prone and potentially racy) than just handing out opaque pointers though.
精彩评论