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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:47:16+00:00 2026-05-18T09:47:16+00:00

Lets assume we’ve got a DLL and there should be an array stored globally

  • 0

Lets assume we’ve got a DLL and there should be an array stored globally in it that’s going to be exported, the thing is we want to initialize it by reading some content from a file, so personally I find myself no other way than putting it in a struct to be able to initialize using constructor:

struct Construction{
 public:
  Construction(){
   //do the initialization thing and read the needed data from the file
  }
  SomeType sTArray[100];
};

__declspec(dllexport) Construction obj();

Now where it’s going to be used, the programmer can initialize a reference to it and then use the reference like below:

SomeType (&arrayRef)[100]=obj.sTArray;

Now would you think I’m wrong in any context?

  • 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-18T09:47:16+00:00Added an answer on May 18, 2026 at 9:47 am

    Yes, you’ve set yourself up for a very nasty surprise at some point.

    1. Global object constructors run during the startup of the C runtime for the DLL.
    2. The C runtime startup code runs during DLLMain.
    3. During DLLMain, you are holding the DLL loader lock.
    4. Your object constructor may involve calls to Win32 api’s that load other system DLL’s.
    5. Tring to load another DLL while already holding the DLL loader lock results in a swift death for your process.

    I’d recommend that you hold off on initializing the array until the first attempt to access it, which will require that you expose the array indirectly as the result of a function call:

    struct Construction{
    public:
      Construction() : bInit(false) {};
      SomeType* GetArray()
      {
        if(!bInit)
        {
          //do the initialization thing and read the needed data from the file
          bInit = true;
        }
        return sTArray;
      };
    private:
      SomeType sTArray[100];
      bool bInit;
    };
    
    __declspec(dllexport) Construction obj();
    

    Of course, this would need to be split into separate header and implementation files.

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

Sidebar

Related Questions

Lets assume that some class is not reachable, but there are another anonymous classes
Lets assume I have a list of objects in an array and i want
Lets assume that I'm dealing with a service that involves sending large amounts of
Lets assume a simple Spring MVC Controller that receives the ID of a domain
Lets assume that a rule (or rule of thumb, anyway), has been imposed in
Lets assume i got 3 .flv files in a folder. How can i create
Lets assume I want to save the count of datagrid rows which can be
Lets assume that I have a computer which has a multicore processor and a
For argument's sake lets assume a HTML parser. I've read that it tokenizes everything
well, i have network that each proxy (lets assume we have 200 proxies), send

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.