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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:35:05+00:00 2026-05-23T21:35:05+00:00

sI’m on Windows and I’m building a C++ project with VS2008. I’m trying to

  • 0

sI’m on Windows and I’m building a C++ project with VS2008. I’m trying to replace new/delete/malloc/free etc. Which is working i.e. my replacements are getting called.

However my replacement allocator needs to be initialised. I have done this thus far by defining it as a global variable in a .cpp file with the #pragma init_seg(lib) defined inside it.

This worked up until recently when std::locale started to get initialised which was calling new before my allocator was getting initialised. So I nervously moved my allocator’s global variable to the compiler segment ie #pragma init_seg(compiler).

This worked for a bit and then I decided to override malloc. Now I get a malloc call in __crtGetStringTypeA_stat in _tmainCRTStartup which is before even the global vars in the compiler segment have been initialised.

Is there any way to get my variable be instantiated before the CRT start up. The only thing I can think of is rebuilding my crt lib and trying some how to insert my initialisation code in there some where. I presume there must be a crt clean up function as well?

Is there an easier route to this and/or something obvious I’m missing here?

  • 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-23T21:35:05+00:00Added an answer on May 23, 2026 at 9:35 pm

    You are using a static storage duration object.

    But you are having problems with the order of initialization.
    To solve this use a static storage duration object that is defined within a function scope.

    MyAllocator& getAllocator()
    {
        static  MyAllocator  allocator;  // Note the static here.
                                         // It has the appropriate lifespan and will be destoryed.
                                         // and is automatically constructed the first time this
                                         // function is called.
        return allocator;
    }
    

    Now your versions of new/delete/ etc can get a reference to the allocator by calling getAllocator(). This will guarantee that the object is correctly initialized (assuming MyAllocator has the correct constructor).

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I've got a string that has curly quotes in it. I'd like to replace
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

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.