🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Can you Dynamically allocate Functions?

Started by
1 comment, last by Jeff D 22 years, 7 months ago
I just learned that the name of a function is actually a pointer to that function just like arrays. So can you dynamically allocate functions? Thx Jeff D Suffered seven plagues, but refused to let the slaves go free. ~ Ross Atherton
Suffered seven plagues, but refused to let the slaves go free. ~ Ross Atherton
Advertisement
quote: Original post by Jeff D
So can you dynamically allocate functions?

While, yes, technically you can (it isn''t pretty, and it''s OS specific) dynamically allocating an array of function pointers has nothing to do with allocating functions . An easier method of not-quite ''allocating functions'' is to load them from a dynamic library (for example: a DLL).

[Resist Windows XP''s Invasive Production Activation Technology!]
dynamically allocated fucntions is very bad practice (unless you are uber asm self modifing code writer that knows machine langauge). Stick to using DLLs (or shared objects for you *nix users). If you keep the function semantics the same across multple dynamic libraries you can then load the implementation of the functions you want (the parms and return varibles have to be the same) by loading the correct library. you could even setup classes and have create funtions which you call to create the class which contains the implemnetation you wish to use. in this case you could even keep all the implementations in the same library as long as the create class functions have different names. personally though i use a different dll for each type of dynamic class i woudl need (for codec plugins in my demo which allow easier reading/writing of different picture formats, since the super class handles the loading of the dlls and the classes and i just call Load("thepicture.ext") and the code checks the entension and uses the approiate class to decode the pciture into a usable format by the demo)

This topic is closed to new replies.

Advertisement