首页 > 解决方案 > C++/WinRT:将关键字放在运行时类实现上是否有意义?

问题描述

我正在尝试最大化我的 UWP 客户端应用程序性能,以弥补我不是作者的缓慢后端。

在一些微软的视频中,我看到放入[noexcept]IDL 类可以使方法调用更高效,但是它们的 C++ 实现呢?由于整个事物是基于 COM 的,并且这些方法的调用方式与原始 C++ 中的方式不同,因此是否会更改诸如inline、之类的关键字noexcept或更改任何内容?const

// MyViewModel.idl
namespace MyApp
{
    [bindable]
    [default_interface]
    runtimeclass MyViewModel 
    {
        MyViewModel();
        [noexcept] Int32 MyProperty;
    }
}

// MyViewModel.h
namespace winrt::MyApp::implementation
{
    struct MyViewModel : MyViewModelT<MyViewModel>
    {
        MyViewModel() = default;

        inline int32_t MyProperty() const noexcept;
        inline void MyProperty(int32_t) noexcept;

        private:
        int32_t m_myProperty;
    };
}

// MyViewModel.cpp
namespace winrt::MyApp::implementation
{
    inline int32_t MyViewModel::MyProperty() const noexcept
    {
        return m_myProperty;
    }

    inline void MyViewModel::MyProperty(int32_t value) noexcept
    {
        m_myProperty = value;
    }
}

此问题严格针对提到的关键字,请不要发布其他无关的优化提示。

标签: c++performanceuwpwindows-runtimeidl

解决方案


推荐阅读