Anyone need a developer?

This forums is for OS project announcements including project openings, new releases, update notices, test requests, and job openings (both paying and volunteer).
User avatar
bluecode
Member
Member
Posts: 202
Joined: Wed Nov 17, 2004 12:00 am
Location: Germany
Contact:

Post by bluecode »

Wave wrote:The only (and I really do mean only) overhead of calling a function in another class is that the function pointer will have to be passed on the stack.
You mean the this pointer/pointer to the class instance not the function pointer. This is only true for 'normal' (member) function calls, not for (pure) virtual functions.

Just a sidenote for those interested: There is a Technical Report on C++ Performace made by the standards commitee. I did not yet read it but it seems to be quite interesting.

btw. we are totally off topic...
elfenix
Member
Member
Posts: 50
Joined: Sun Dec 02, 2007 1:24 pm
Libera.chat IRC: elfenix
Location: United States
Contact:

Post by elfenix »

Wave wrote:The only (and I really do mean only) overhead of calling a function in another class is that the function pointer will have to be passed on the stack.

So the overhead of myClass.myFunc(a) is exactly the same as of myFunc(&myInstance, a).

Continuing the off-topic thread here, just thought I'd clarify what I was talking about in my original post. I was discussing the idea of inheriting objects from the kernel in a userspace module in a microkernel.

So, the kernel would have a class Foo with methods. These would then be exported with whatever syscall routine you wanted.

Then, userspace space would implement class Foo(1) which implemented all those methods as syscalls.

Then your drive would inherit from class Foo(1) and method calls would then become syscalls into the kernel.

And, as I said before, that has significant overhead that you would need to account for/keep track of. I considered this design path before, but didn't really care for it because of that.

Which reminds me....

Most C function calls in a dynamic library are very similar to C++ virtual function calls in that you are still going through some indirection. C libraries have something very much akin to a v-table that is going to be used when you call a function that is not statically linked. Most people don't usually realize it's there.

Btw: what's the problem with pointing to functions within classes? Is there something wrong with something like this? This actually has the benefits of type-safety (among other things).

Code: Select all

#include <iostream>

class F1
{
    public:
        virtual void weird(int i) = 0;
};

class F2 : public F1
{
    public:
        virtual void weird(int i) 
            { std::cout << "F2 - " << i << std::endl; }
};

class F3 : public F1
{
    public:
        virtual void weird(int i) 
            { std::cout << "F3 - " << i << std::endl; }
};

int main()
{
    F1 *my_f2 = new F2();
    F1 *my_f3 = new F3();
    void (F1::*func)(int i) = &F1::weird;

    (my_f2->*func)(5);
    (my_f3->*func)(6);

    delete my_f2;
    delete my_f3;
}
Post Reply