none
cmath or System::Math RRS feed

  • Question

  • Hi,

    It is a Windows Application project that uses .NET framework.

    C++ always allow to use either cmath library or System::Math class.

    What is recommended to use?

    The same question for cstring and System::String?

    Thanks

    Thursday, July 18, 2013 8:36 PM

Answers

  • I don't think there's a straight answer to this. In general I'd say to stick to System::Math and System:String if this is a C++/CLI project.

    Using cmath may have a negative impact on performance because math function that in native C++ can be treated as intrinsics are going to be real function calls in C++/CLI. But the JIT compiler recognizes some of the System::Math functions and may generate code that's faster than a function call.

    Using cstring can be problematic because all the .NET framework uses System::String, you'll probably have to convert back and forth between std::string and System::String. It's not efficient and complicates the code.

    That said, if the logic, non-UI part of the program is large and complex you may want to write it in native C++ so you don't take an unnecessary dependency on C++/CLI. How knows, maybe later you'll want to reuse the code for something else and native C++ code is obviously more portable than C++/CLI.

    • Marked as answer by BGQQ Friday, July 19, 2013 2:59 PM
    Thursday, July 18, 2013 9:27 PM
    Moderator