How expensive are callbacks?

I am creating a rendering engine. And theres 2 ways to create a task management system. Creating my own custom callbacks, called before and after rendering, or implementing a task management system in which I would have to get the class from the parent TaskClass, and then drop it into the queue.

Honestly, I feel that creating callbacks is better because it allows me to create a task management subsystem that is independent of the actual rendering mechanism. This allows me to focus more on the rendering engine and worry about task management later.

But my question is ... "is it expensive to use callbacks?" Is this a common practice in an intensive processor environment such as a game engine.

+3
source share
7 answers

First of all, relative is expensive if you call these callbacks at a frequency of 10,000 Hz, yes, some callback implementations can be too expensive. However, a simple callback based on a pointer function will in fact have no overhead.

: , , , , 60 30 /. . , , , , . , AI-.

: GPU, CPU;).

+5

C

void func1() { }

void func2() 
{
  void (*funcptr)() = func1;

  func1();
  funcptr();
}

gcc -S func2:

movq $func1, -8(%rbp)
movl $0, %eax
call func1
movq -8(%rbp), %rdx
movl $0, %eax
call *%rdx

, , , .. .

+5

- . , , , - , , .

, - . , , . .

+2

, .

.

0

, , . , / .. .

0

" ?"

.

: , , / .

: / , - , , ( , , , ), .

0

Visual Studio , Concurrency Runtime, Parallel Pattern Library Agents Library VS 2010 .

, .

0

Source: https://habr.com/ru/post/1750978/


All Articles