Dynamic Class Loading Idea
Craig Black
craigblack2 at cox.net
Fri Nov 2 23:26:42 PDT 2007
Dynamic class loading has the requirement that the class library can be
loaded at run time. Traditionally, this means that all functions had to be
bound via function pointers or virtual functions. This would mean that all
the local functions would have to be virtual, and static/global functions
would need to be bound via function pointers somehow. This is obviously a
performance issue.
However, self modifying code could be employed to load a class at run time
without using function pointers and virtual functions. For each function in
a dynamically loadable class, we could have an array of pointers that would
point to the addresses in code where that function is called (call sites).
Before the class library is loaded, these call sites would simply throw
exceptions. When the class is loaded, the code at the call site to throw
the exception could be overwritten to call the appropriate function. This
would eliminate the requirement to use function pointers/virtual functions
and allow us to do high-performance dynamic class loading.
I don't know if it is possible to modify functions that reside in the code
segment. Does the operating system allow this? If not, we could place
functions with these dynamic call sites on the heap.
Thoughts?
-Craig
More information about the Digitalmars-d
mailing list