I'm currently using opaque pointers as my standard technique for encapsulation, but looking at the OpenGL API makes me think that using id numbers could be a better choice. I would like some advice from seasoned C programmers (I've only been using the language actively for ~2 years).
Here are my initial thoughts that I would like confirmed or corrected.
Possible pros for Id numbers:
Using object/memory pools in the implementation is rather straight forward if using id numbers
The id number does not have to map to the system memory (could reference graphics memory in the GL case)
Possible cons for Id numbers:
- Makes the implementation slightly more complex
There is a similar question that takes into account the situation of using shared libraries: Should I use integer ID or pointers for my opaque objects? My question is not about shared libraries, it's about the general case of hiding implementation details from user code.
I suppose you could typedef a MyObjectHandle to enable the library to switch between id number and opaque pointer.
The question is: What are the pros and cons for opaque pointers vs id numbers using the C programming language?