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 8957055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:54:02+00:00 2026-06-15T14:54:02+00:00

We have central classes and functions in our big project to abstract from the

  • 0

We have central classes and functions in our big project to abstract from the actual platform types, e.g. mutex, file, thread etc. instead of having “fopen” everywhere in the code. While this is good, I would like to go even further and don’t have any system includes in the header files (like #include <windows.h>), which would be true platform abstraction and faster compilation. On the downside you cannot just typedef to a system type (e.g. Windows HANDLE).

Option 1: PImpl-idiom

class RwMutex
{
    // .....
private:
   struct Impl;
   Impl*   m_Impl;
}
  • Pro: Implementation and platform types well hidden in Cpp.
  • Con: Involves 2-stage construction (the ‘new’, we don’t have exception) which can fail. Laborious to do.

Option 2: Namespace functions

class RwMutex {
public:
    bool LockRead() {return RwMutexLockRead( this );}
private:
    char m_AnonymousMember[ 16 ];
}
bool RwMutexLockRead( RwMutex* p );
  • Pro: The implementation can be just linked to it, ideal for placing it into a library on its own.
  • Con: Involves reinterpret_cast of the space which holds the member. Not nice in the debugger. Also a lot of work.

Maybe I’m to eager on it, but it would be cool if the huge amount of project code would be clean of any platform-dependent includes, maybe enforced by the -nostdinc option.

  • 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-06-15T14:54:03+00:00Added an answer on June 15, 2026 at 2:54 pm

    Option 1 using pointers is a bad idea. Use either boost::scoped_ptr or, if you can, std::unique_ptr.

    Option 2, as you implement it, should not be used. See GotW #28: The Fast Pimpl Idiom. In C++11 however, this can be done correctly using std::aligned_storage<>. I once wrote a pimpl_ptr<T, Size, Align=default> that does the casting, copying, destructor call for you and checks that you have chosen the right Size.

    In general, use pimpl unless you have profiled and shown that this is the bottleneck.

    But as always, don’t reinvent the wheel. Mutex and Threads are part of the new C++11 standard, so either upgrade the compiler or use Boost instead. For files use Boost. The reasoning is, that many parts of the new C++11 library are taken from Boost.

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

Sidebar

Related Questions

We have a Library Project that we use for all our central reused code
I have a Lucene Index on a central file system. In my IIS application,
With a PHP MVC project, I have a few model classes that load data
I have a central application which is going to receive messages from various services
I have a central database and a unique database for a project I am
I have a problem with a TPH mapping. Here are the classes : Abstract
I have a central Git bare repository. When a push is made to that
I have a central git repository that everyone pushes to for testing and integration,
For the company I am contracted to, they have a central office in Denver
I've implemented a REST-based API (using Tonic, FWIW) so I have a central dispatch.php

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.