I have a function which takes an object of a custom class. A member of this object should store an identifier of that function (or a 'reference' to that function) so that the function can determine whether it was called before with this object.
What is a suitable identfier for this purpose?
I am not necessarily talking about the function name, because overloaded functions share the same name, so this doesn't work.
Is the function address (as used für delegates) a proper way? I am pretty sure that this will work, but not 100% sure. Or may the function be moved around by the garbage collector like regular objects?
Is there maybe another, better way to get a 'function ID'?
Edit
Here's an example to demonstrate my requirement (pseudo-code used):
void WorkerFunction (CFuncStep i_oFS)
{
if (i_oFS.FunctionID == WorkerFunction.FunctionID)
{
// continue work
}
else
{
// start work
i_oFS.FunctionID = WorkerFunction.FunctionID;
}
if (finished_work)
i_oFS.FunctionID = null;
}
The purpose is saving the operation state and later continuing an operation in a called function. This makes sense in cases e.g. where the function does network communication and has to wait for the reply. The func returns immediately so that the thread can do other work. Later it comes back to fetch the reply.
I could use a separate thread, but I want to avoid the overhead of thread sync here, because it would not just be 1 add. thread, but quite some.