Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion. Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules. |
27th December 2019, 21:43 | #1 | Link |
Registered User
Join Date: Jun 2002
Location: On thin ice
Posts: 6,837
|
C++ performance problem
Why is func1 100 times faster than the func2?
Code:
extern "C" { __declspec(dllexport) LPVOID __stdcall func1() { CmyInterface* pTest = new CmyInterface(); LPVOID pMyInterface; pTest->QueryInterface(__uuidof(ImyInterface), &pMyInterface); return pMyInterface; } __declspec(dllexport) ImyInterface* __stdcall func2() { return (ImyInterface*) new CmyInterface(); } } https://www.codeproject.com/Articles...out-ATL-or-MFC and other is that: Code:
#include "pch.h" #include <ComDef.h> #include <atomic> // {864C3D72-B6FD-4014-8AB4-55B664FAEF2C} static const GUID CLSID_BasicServer = { 0x864c3d72, 0xb6fd, 0x4014, { 0x8a, 0xb4, 0x55, 0xb6, 0x64, 0xfa, 0xef, 0x2c } }; // {177D3798-3D6D-4217-B355-D2355884CFDF} static const GUID IID_IBasicServer = { 0x177d3798, 0x3d6d, 0x4217, { 0xb3, 0x55, 0xd2, 0x35, 0x58, 0x84, 0xcf, 0xdf } }; struct IBasicServer : IUnknown { virtual int __stdcall GetFive() = 0; }; class BasicServer : IBasicServer { private: std::atomic<int> m_refs = 0; public: // IUnknown HRESULT __stdcall QueryInterface(const IID& iid, void** ppv); ULONG __stdcall AddRef(); ULONG __stdcall Release(); // IBasicServer int __stdcall GetFive(); }; // IUnknown STDMETHODIMP BasicServer::QueryInterface(const IID& iid, void** ppv) { if (!ppv) return E_POINTER; if (iid == IID_IUnknown) { *ppv = (IUnknown*)this; } else if (iid == IID_IBasicServer) { *ppv = (IBasicServer*)this; } else { *ppv = nullptr; return E_NOINTERFACE; } AddRef(); return S_OK; } STDMETHODIMP_(ULONG) BasicServer::AddRef() { return ++m_refs; } STDMETHODIMP_(ULONG) BasicServer::Release() { int refs = --m_refs; if (!refs) delete this; return refs; } // IBasicServer int __stdcall BasicServer::GetFive() { return 5; } // Extern extern "C" { __declspec(dllexport) LPVOID __stdcall CreateBasicServer() { BasicServer* pServer = new BasicServer(); LPVOID pIBasicServer; pServer->QueryInterface(IID_IBasicServer, &pIBasicServer); return pIBasicServer; } }
__________________
https://github.com/stax76/software-list https://www.youtube.com/@stax76/playlists Last edited by stax76; 27th December 2019 at 21:47. |
|
|