Archived

This topic is now archived and is closed to further replies.

frizb

A simple *Func question

Recommended Posts

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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites
Function pointers to not need to be deleted because functions are not allocated memory.

And function pointers are declared:

int (*myMonsterAI)( args )

and not:

int* myMonsterAI();

The latter example returns an integer pointer.

Michael

Share this post


Link to post
Share on other sites