0

I want to be able to programmatically (or at least using the Project properties) set gcAllowVeryLargeObjects to true. I know I can use the App.config file, but this is quite ugly as it needs to create a separate file to the main executable which then needs to be passed around with the executable.

I've experimented with both Environment.GetEnvironmentVariable("gcAllowVeryLargeObjects") and Environment.GetEnvironmentVariable("COMPlus_gcAllowVeryLargeObjects"), but it doesn't print out anything, even if I set gcAllowVeryLargeObjects to true using a config file.

If that doesn't work, I don't expect Environment.SetEnvironmentVariable() to work either, and sure enough, it doesn't.

I've had a good look in the Project properties of VS2022, and there's nothing to be seen there either.

Dan W
  • 3,520
  • 7
  • 42
  • 69
  • If the docs say "do it in the app.config", why should an environment variable work? They are global. You don't want this setting for all apps on the PC. – Thomas Weller Apr 13 '22 at 20:18
  • You really ship a single executable, not an installer? But you don't need to ship this file. The app could create it itself if it does not exist, and then restart itself. – Thomas Weller Apr 13 '22 at 20:20
  • @ThomasWeller: I'm a massive fan of distributing single exes, rather than installation files or zips (because I love everything ultra portable and independent), but that's not my purpose here. Sometimes, I copy files around different PCs in my home, and I forgot again to copy the config file too. I wasted at least an hour trying to figure the problem out. I'm sick of an extra "tag-along" file, and I just want the setting to be compiled *into* the exe. – Dan W Apr 13 '22 at 20:26
  • It's probably possible to have a data structure that doesn't need very large objects – Thomas Weller Apr 13 '22 at 20:28
  • @ThomasWeller: I do since without this setting, the app will potentially crash. A lot of data is needed for the caching. – Dan W Apr 13 '22 at 20:28
  • @ThomasWeller: Lol, not in many cases. Data scientists have been begging Microsoft for ages to allow better support for super large arrays and gigantic objects. Only lately have they improved somewhat in this regard. Personally, I need a giant amount of keys in a Dictionary since it acts as a cache for a table exploring potentially around a trillion nodes. – Dan W Apr 13 '22 at 20:31
  • If you need a BigArray implmentation, there is https://github.com/dotnetbio/bio/blob/master/Source/Bio.Core/BigArray.cs Don't know if they also have a dictionary. I found it when I was about to [write my own](https://github.com/WelliSolutions/HugeArray) – Thomas Weller Apr 13 '22 at 20:32

1 Answers1

1

It isn't possible.

But you can workaround it:

  1. Make the app.config an embedded resource or similar.
  2. At startup, check if the file exists.
  3. If it doesn't, read the resource and write the file.
  4. Let the app restart itself.
Thomas Weller
  • 55,411
  • 20
  • 125
  • 222
  • Thanks, that's surprisingly ugly. I'm surprised MS haven't got on top of this by now. It's a setting the user should not be able to adjust so seems out of place in a config file. – Dan W Apr 13 '22 at 20:57