question

DarabanStefanRBROEES-5020 avatar image
0 Votes"
DarabanStefanRBROEES-5020 asked rupeshshukla-4529 edited

How to store variables in a created section

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://docs.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!


c++
· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Maybe the data_seg pragma would be more convenient for you.


1 Vote 1 ·

Thank you @RLWA32-6355 . How can I use data_seg for a .lib file?

0 Votes 0 ·
RLWA32-6355 avatar image RLWA32-6355 DarabanStefanRBROEES-5020 ·

For a static library the individual modules would need to be compiled using the data_seg pragma.

0 Votes 0 ·
RLWA32-6355 avatar image RLWA32-6355 DarabanStefanRBROEES-5020 ·

And you could use the bss_seg pragma in the same way for uninitialized data.

0 Votes 0 ·

@DarabanStefanRBROEES-5020

As far as I'm concerned, there is no method to configure from the build environment to achieve this effect.

0 Votes 0 ·

1 Answer

rupeshshukla-4529 avatar image
1 Vote"
rupeshshukla-4529 answered rupeshshukla-4529 edited

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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.