Re: home made handle
On Apr 9, 10:02 pm, "Christopher Pisz" <some...@somewhere.net> wrote:
How would you go about giving some unique identifier back to a user, that
they can use to make calls to your module with, that is associated with a
pointer to an object in your multithreaded module?
I thought about something like
typedef ModuleObject * ID;
where ModuleObject is a class in my multithreaded module.
objects of the ModuleObject type frequently get allocated and
released from memory. and I have a private list of
ModuleObject pointers in my module.
, but I don't really want them to have access to the methods of the object
since it is multithreaded and more importantly, they have no business
calling methods directly, but should be calling the functions in the modu=
le.
There are several solutions. The simplest is the one you just
described. If all the user sees is an incomplete declaration of
ModuleObject, they won't be able to misuse it too much.
If you don't want to do that, there's always void*. And if even
revealing the fact that it is a pointer is too much for you,
then you can keep pointers to the objects in a vector, and
return an index to that. In practice, I don't see any reason to
go with the additional complexity, but this solution may be
useful in cases where you keep the objects themselves in the
vector (reusing them as needed), rather than a pointer.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34