int main()
{
˙˙˙˙thread_local int i;
˙˙˙˙MEMORY_BASIC_INFORMATION mbi;
˙˙˙˙if( !VirtualQueryEx( GetCurrentProcess(), &i, &mbi, sizeof mbi ) )
˙˙˙˙˙˙˙ return EXIT_FAILURE;
˙˙˙˙cout << "allocation base: " << (void *)mbi.AllocationBase << endl;
˙˙˙˙cout << "region base:˙˙˙˙ " << (void *)mbi.BaseAddress << endl;
˙˙˙˙cout << "&i:˙˙˙˙˙˙˙˙˙˙˙˙˙ " << (void *)&i << endl;
˙˙˙˙cout << "region size:˙˙˙˙ " << (double)mbi.RegionSize / 0x1.0p12;
˙˙˙˙cout << " pages" << endl;
}
#include <Windows.h>
#include <iostream>
using namespace std;
int main()
{
˙˙˙˙thread_local int i;
˙˙˙˙MEMORY_BASIC_INFORMATION mbi;
˙˙˙˙if( !VirtualQueryEx( GetCurrentProcess(), &i, &mbi, sizeof mbi ) )
˙˙˙˙˙˙˙ return EXIT_FAILURE;
˙˙˙˙cout << "allocation base: " << (void *)mbi.AllocationBase << endl;
˙˙˙˙cout << "region base:˙˙˙˙ " << (void *)mbi.BaseAddress << endl;
˙˙˙˙cout << "&i:˙˙˙˙˙˙˙˙˙˙˙˙˙ " << (void *)&i << endl;
˙˙˙˙cout << "region size:˙˙˙˙ " << (double)mbi.RegionSize / 0x1.0p12;
˙˙˙˙cout << " pages" << endl;
}
iirc, in the .tdata or .tss. But that might be for ELF. For Windows,
damn... iirc, in the TIB?
https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-tlsalloc
Am 15.11.2026 um 21:40 schrieb Chris M. Thomasson:
iirc, in the .tdata or .tss. But that might be for ELF. For Windows,
damn... iirc, in the TIB?
As thread-local data is per thread it isn't in the executable image.
At least for Windows.
https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/
nf-processthreadsapi-tlsalloc
This is to allocate a TLS-slot for a new image.
You almost never need this.
What about:
__declspec(thread) int x;
On 11/17/2026 3:04 AM, Bonita Montero wrote:
As thread-local data is per thread it isn't in the executable image.
At least for Windows.
What about:
__declspec(thread) int x;
Am 18.11.2026 um 01:09 schrieb Chris M. Thomasson:
On 11/17/2026 3:04 AM, Bonita Montero wrote:
As thread-local data is per thread it isn't in the executable image.
At least for Windows.
What about:
__declspec(thread) int x;
Better use C++11's thread_local since it cares for constructors
and destructors.
Yeah. Also, in a dll: TlsAlloc and friends are the way to go.
Iirc, in DLLMain, set everything up.
Am 18.11.2026 um 21:59 schrieb Chris M. Thomasson:
Yeah. Also, in a dll: TlsAlloc and friends are the way to go.
Iirc, in DLLMain, set everything up.
You can write your own DllMain without honouring TlsAlloc.
The kernel does everything for you and places the right
TLS-index in the thread-information block.
Its been a while since I created a lot of DLL's in Windows, but: https://learn.microsoft.com/en-us/windows/win32/dlls/using-thread-local- storage-in-a-dynamic-link-library
| Sysop: | Tetrazocine |
|---|---|
| Location: | Melbourne, VIC, Australia |
| Users: | 3 |
| Nodes: | 8 (0 / 8) |
| Uptime: | 51:07:15 |
| Calls: | 223 |
| Files: | 21,513 |
| Messages: | 83,425 |