Dynamic Class Loading Idea

Vladimir Panteleev thecybershadow at gmail.com
Sat Nov 3 03:41:42 PDT 2007


On Sat, 03 Nov 2007 08:26:42 +0200, Craig Black <craigblack2 at cox.net> wrote:

> 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?

I like DDL's approach, in which it acts as a run-time linker. It uses relocation data in OBJ files to find address references and fix them (thus "relocating" the code for any memory address) when loading the libraries. 

-- 
Best regards,
 Vladimir                          mailto:thecybershadow at gmail.com



More information about the Digitalmars-d mailing list