Jump to content
  • Advertisement

Archived

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

frizb

A simple *Func question

This topic is 6607 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!