Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 557389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:01:16+00:00 2026-05-13T12:01:16+00:00

I have a library written in C and I have 2 applications written in

  • 0

I have a library written in C and I have 2 applications written in C++ and C. This library is a communication library, so one of the API calls looks like this:

int source_send( source_t* source, const char* data );

In the C app the code does something like this:

source_t* source = source_create();
for( int i = 0; i < count; ++i )
    source_send( source, "test" );

Where as the C++ app does this:

struct Source
{
    Source()
    {
        _source = source_create();
    }

    bool send( const std::string& data )
    {
        source_send( _source, data.c_str() );
    }

    source_t* _source;
};

int main()
{
    Source* source = new Source();
    for( int i = 0; i < count; ++i )
        source->send( "test" );
}

On a Intel Core i7 the C++ code produces almost exactly 50% more messages per second..
Whereas on a Intel Core 2 Duo it produces almost exactly the same amount of messages per second. ( The core i7 has 4 cores with 2 processing threads each )

I am curious what kind of magic the hardware performs to pull this off. I have some theories but I thought I would get a real answer 🙂

Edit: Additional information from comments

Compiler is visual C++, so this is a windows box (both of them)

The implementation of the communication library creates a new thread to send messages on. The source_create is what creates this thread.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T12:01:16+00:00Added an answer on May 13, 2026 at 12:01 pm

    From examining your source code alone, I can’t see any reason why the C++ code should be faster.

    The next thing I would do is check out the assembly code that is being generated. If you are using a GNU toolchain, you have a couple of ways to do that.

    You can ask gcc and g++ to output the assembly code via the -S command line argument. Make sure that other then adding that argument, you use the exact same command line arguments that you do for a regular compile.

    A second option is to load your program with gdb and use the disas command.

    Good luck.

    Update

    You can do the same things with the Microsoft Toolchain.

    To get the compiler to output assembly, you can use either /FA or /FAs. The first should output assembly only while the second will mix assembly and source (which should make it easier to follow).

    As for using the debugger, once you have the debugger started in Visual Studio, navigate to “Debug | Windows | Disassembly” (verified on Visual Studio 2005, other versions may vary).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a library written in C++, and a wrapper for this library written
I have a library written in C that I would like to use in
I have a dynamic linked library written in C# 3.0. This library has a
I have written some code that makes use of an open source library to
for one of my applications I'd like to provide a minimal web interface. This
I have a shared library written in C++ that I'd like to use with
I have a library written in C++/CLI and I want to open it up.
I have a date picker library written for MooTools that I want to port
In physics library written in C# I have the following code: (in ContactManager.cs) public
I have a simple class library (COM+ service) written in C# to consume 5

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.