Garbage Collection and small objects
-
My program loads objects that are approximately 100 bytes in size from a SQLite database. It loads about 4 million of them and the resulting process memory usage grows to around 1 GB. I'm looking to speed this up greatly, because right now it takes 40 seconds to load all the objects. In the Visual Studio debugging tools memory usage window, it shows that garbage collections are occurring five or six times per second during this loading process. So I started looking into ways to suppress the garbage collector, thinking that that could make a difference. I found the function
public static bool TryStartNoGCRegion (long totalSize);
Supposedly this allows you to allocate a large segment of memory up front and cause the GC to be less aggressive. So I calculate the size I need by multiplying 100 bytes times 4 million objects, or around 400 MB. But when I call the function with 400 million as the requested size, it fails with an
ArgumentOutOfRange
exception. Is it unrealistic to think I can allocate that much in one go, or there something else wrong? Does anyone know how to use this function? (Machine has 64 GB of RAM.)The difficult we do right away... ...the impossible takes slightly longer.