How to store variables in a created section

Daraban Stefan (RBRO/EES) 21 Reputation points
2021-07-19T05:44:47.447+00:00

Hello,

I have 109 files in my build environment and besides these I also have a library. All the variables from the files that I have in the build environment and in the library are currently stored in the .data and .bss area. I would like to create a new section and store all variables (global) from my files and my library in here.

I have tried using the pragma #pragma section and then use __declspec(allocate("mysec")):
https://learn.microsoft.com/en-us/cpp/preprocessor/section?view=msvc-160&viewFallbackFrom=vs-2019

If I use this method, I need to use __declspec(allocate("mysec")) for each variable. I am using Microsoft Visual Studio 2015/2017 (Professional).

Is there a method to configure from the build environment that for a certain file/library, all the variable should be stored in the "mysec" section?

Thank you!

Developer technologies C++
{count} votes

1 answer

Sort by: Most helpful
  1. rupesh shukla 16 Reputation points
    2021-07-19T15:04:04.487+00:00

    What is the purpose of storing all global variable. Do you really need data segment . It is basically used to share memory between process . What kind of application it is . See if you just want to share variables between dll and exe . Why not put all of your variables in some structure and then share the structure etc.

    Thanks

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.