Code design/optimization

Using GLFW
Mattias
2013-10-10
2013-10-10
  • Mattias

    Mattias - 2013-10-10

    First of all. I have followed glfw for some time and like the basic functions of it. :)
    But i have been looking into the code of glfw and there seams to be some unnecessary overhead for functions/design flaw.
    For example when calling: glfwGetTime() that functions calls: _glfwPlatformGetTime() and that functions calls: getRawTime() and that functions calls the OS timer function.
    Why not make just make glfwGetTime get the time from the OS directly? Could easily be done with #ifdef for example.

    Just my thoughts.

     
  • Doug Binks

    Doug Binks - 2013-10-10

    Most compilers can optimize away internal function calls like these. The design makes platform changes easier and safer to make since any changes are local to a given platform.

     
  • Camilla Löwy

    Camilla Löwy - 2013-10-10

    It's done that way because GLFW isn't nearly performance critical enough to violate consistent design and any cost a few function calls within GLFW incurs is dwarfed by the actual syscall. Then there are the optimisations Doug mentions.

    Some of the _glfwPlatform functions also perform a lot of work and all of them perform at least some. Duplicating that code across every platform's implementation would make the code larger, more bug-prone and difficult to maintain. You can see the ifdef model used in freeglut, although they are now moving away from it due to the difficulty of supporting more than two platforms with it.