3 ms·
If 512mb are needed as contiguous space, then one hacky solution is do define a BSS section of 512mb, or in "C" terms - global array - char mem[512 * 1024 * 10
by malkia 15y ago
If 512mb are needed as contiguous space, then one hacky solution is do define a BSS section of 512mb, or in "C" terms - global array -
char mem[512 * 1024 * 1024];
the executable loader would "allocate" this memory before loading any dlls, and later dlls that were supposed to be in that memory would be rebased
Oh, and somehow Go would need to use this memory rather than allocate it.
- moldbug 15y agoI wouldn't call this "hacky" - it's exactly the right way to do it. For one thing, it makes the address of your arena constant. Unfortunately my experience is that a lot of C environments handle this very poorly.
- malkia 15y agoI called this hacky, as it would only work for executables, if this was in a dll/dylib/so shared library, then it might even make the things worse, as now even more stricter contiguous space would be neeeded. For example, if the language runtime was loaded as plugin or something. So one has to be aware that is not always the good solution for all purposes, hence hacky :)
- barrkel 15y agoThis would, however, allocate memory rather than just address space. (Yes, it may be lazily committed, but it's still not as cheap as address space.)
- malkia 15y agoOnce this is done, you can VirtualFree it (starting/ending from page boundaries), and let it back to the OS. Yes for some short amount of time, while it loads and goes to your code the memory is reserved.