|Just hold make an internal array of PCore pointers and pass them out an Index number ... call it a handle ... I guess a HPCORE.
So they hold onto an index number and when they call a function the pass in the index number and you grab back the PCore pointer out of your array.
That is what all the HANDLES are in Windows, they have a number it tells them nothing about what happens internally it just a index to a internal pointer that never comes out. So you code becomes more like Windows API and they can have multiple HPCore handles.
HPCORE hPCore = CreateNewPCore();
EDIT: Actually I am being slow do what windows does exactly pass back a pointer to the position in the internal array rather than the index as the handle. First saves having to use the number to traverse the array to get the pointer (so much much faster). Second you can test the handle being valid if you need because it must lie between PCoreArray ... PCoreArray[Last] of your internal PCore pointer array. It's index position in the array which you only need to know when you dispose to empty the slot is straight forward
Handle Index = (Handle - &PCoreArray)/sizeof(Pointer).
So a handle is a PCore** .. that is a pointer to a pointer to a PCore but I would just typedef it as size_t and internally typecast it because you can check it via the above. So ...
typedef size_t HPCORE;
In vino veritas
modified 10-Nov-16 21:33pm.