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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:26:53+00:00 2026-06-01T04:26:53+00:00

I have been reading different articles on memory management in preparing for how I

  • 0

I have been reading different articles on memory management in preparing for how I want my architecture to work, with my biggest worries on how the allocators will be used, created and handled throughout the code base. One of the issues is that my design always has the allocator(s) at a global scope, since I don’t have a typical singleton design to contain the allocators, they have no real place to live. I would like to avoid using globals for this due to all the issues typical had with using globals.

This lead me to the design of having something such as

void* operator new(size_t size, uint32_t type)
{
    return gAllocator.Alloc(size, type);
 }

This would then lead to having just the new definition in a header file, with the declaration in a .cpp. This .cpp file would then have the gAllocator, only in the .cpp file (and can be accessed in place else except for the new call.

If my design would to be like this, would the gAllocator still be a global variable, if not, what type of variable would it be considered? What if it was in the scope of just a namespace?

  • 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-01T04:26:54+00:00Added an answer on June 1, 2026 at 4:26 am

    It seems a plain global is just what you want. For review, in C++ a global (or singleton) should be a local static variable in an inline function.

    class myAllocator {
    public:
        static myAllocator &getDefaultInstance() {
            static myAllocator theInstance( parameters );
            return theInstance;
        }
    };
    

    This way, the object is initialized the first time it’s used. If you use a typical header declaration + .cpp definition, the order of initialization with respect to other globals is undefined, with possible unpredictable consequences. (The “static initialization order fiasco.”)

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

Sidebar

Related Questions

I have been reading a number of articles online suggesting different approaches to migrate
I am trying to learn assembly my self, and I have been reading different
I have been reading the docs and playing with different EventQuery parameters for days
I have been reading through a few articles on PDO and they seem to
I have been reading on the different question talking about selecting unique nodes in
I have been reading tutorials from several different places like http://css-tricks.com/scrollfollow-sidebar/ or http://jqueryfordesigners.com/fixed-floating-elements/ and
I have been reading many articles trying to understand the difference between functional and
I have been reading more lately about the efficiency of the different selector engines.
I have been lately reading a lot on memory allocation schemes in java, and
Have been reading about async and tasks and been attempting to convert the CopyFileEx

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.