The API Registry states that calling get() on an API that hasn’t been loaded yet will return a “struct full of NULL function pointers”, and that when the API is eventually loaded these NULL function pointers will be “replaced by the real function pointers of the API.”
This stumped me for a while. How can a function return a “struct of NULL function pointers”? The only thing I could think of is that get() probably memsets some memory to zero and returns that. After all, the API structs are purely abstract and full of function pointers that lend themselves well to getting initialized to zero.
Assuming that’s the trick, I’m curious… how on earth does the API registry know how MUCH memory to memset and zero? The API registry has no idea (yet) how big any of the API structs that will be loaded will be!
In other words, if the first thing I do is ask the API Registry to get() an API, and the only thing I pass it is the name of the API, how does API registry know how much memory to allocate and zero in order to return it?
Sorry if it’s a nosey question, but this part of the design really struct me and now I’m super curious. The set() function passes in bytes, but that hasn’t been called yet! That’s not called until the DLL loads!
Only thing I can think of is that a its a large hardcoded number and that once the API is set the memory is realloc’d down to the appropriate size. Or maybe it’s more elegant than that. I probably would have just passed the size with the get() function and used that to know how much to return if it’s not ready yet.