A simple *Func question
That depends.
If you store the function pointer in a static variable, i.e. one you declared in the beginning of your program, ex:
int theInt;
you don''t need to delete it. When it goes out of context, it will be automatically deallocated.
But if you store your function pointer in a dynamic variable, i.e. one you declare programmatically as a respond to some kind of action, you definitely need to deallocate it your self or your program will leak.
I''m not completely sure I''m acutally answering your question, then again I''m not completely sure what your question is :-)
Regards
toft
If you store the function pointer in a static variable, i.e. one you declared in the beginning of your program, ex:
int theInt;
you don''t need to delete it. When it goes out of context, it will be automatically deallocated.
But if you store your function pointer in a dynamic variable, i.e. one you declare programmatically as a respond to some kind of action, you definitely need to deallocate it your self or your program will leak.
I''m not completely sure I''m acutally answering your question, then again I''m not completely sure what your question is :-)
Regards
toft
June 19, 2000 09:32 AM
Just to be clear... say you have a function pointer:
int *myMonsterAI;
and at some point you set this to an existing function:
myMonsterAI = hairyMonsterAI;
then no, you don''t need to delete it. The function pointer is only using the space required for a pointer, and has not reserved any extra memory for the function.
Of course, it doesn''t hurt to set the function to NULL when you''re finished with it - for book-keeping if nothing else.
int *myMonsterAI;
and at some point you set this to an existing function:
myMonsterAI = hairyMonsterAI;
then no, you don''t need to delete it. The function pointer is only using the space required for a pointer, and has not reserved any extra memory for the function.
Of course, it doesn''t hurt to set the function to NULL when you''re finished with it - for book-keeping if nothing else.
June 19, 2000 09:33 AM
Just to be clear... say you have a function pointer:
int *myMonsterAI();
and at some point you set this to an existing function:
myMonsterAI = hairyMonsterAI;
then no, you don''t need to delete it. The function pointer is only using the space required for a pointer, and has not reserved any extra memory for the function.
Of course, it doesn''t hurt to set the function to NULL when you''re finished with it - for book-keeping if nothing else.
int *myMonsterAI();
and at some point you set this to an existing function:
myMonsterAI = hairyMonsterAI;
then no, you don''t need to delete it. The function pointer is only using the space required for a pointer, and has not reserved any extra memory for the function.
Of course, it doesn''t hurt to set the function to NULL when you''re finished with it - for book-keeping if nothing else.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement