c# - 'System.OutOfMemoryException' was thrown when there is still plenty of memory free -
c# - 'System.OutOfMemoryException' was thrown when there is still plenty of memory free -
this code:
int size = 100000000; double sizeinmegabytes = (size * 8.0) / 1024.0 / 1024.0; //762 mb double[] randomnumbers = new double[size];
exception: exception of type 'system.outofmemoryexception' thrown.
i have 4gb memory on machine 2.5gb free when start running, there plenty space on pc handle 762mb of 100000000 random numbers. need store many random numbers possible given available memory. when go production there 12gb on box , want create utilize of it.
does clr constrain me default max memory start with? , how request more?
update
i thought breaking smaller chunks , incrementally adding memory requirements help if issue due memory fragmentation, doesn't i can't past total arraylist size of 256mb regardless of tweaking blocksize.
private static irandomgenerator rnd = new mersennetwister(); private static idistribution dist = new discretenormaldistribution(1048576); private static list<double> ndrandomnumbers = new list<double>(); private static void addndrandomnumbers(int numberofrandomnumbers) { (int = 0; < numberofrandomnumbers; i++) { ndrandomnumbers.add(dist.icdf(rnd.nextuniform())); } }
from main method:
int blocksize = 1000000; while (true) { seek { addndrandomnumbers(blocksize); } grab (system.outofmemoryexception ex) { break; } } double arraytotalsizeinmegabytes = (ndrandomnumbers.count * 8.0) / 1024.0 / 1024.0;
you may want read this: "“out of memory” not refer physical memory" eric lippert.
in short, , simplified, "out of memory" not mean amount of available memory small. mutual reason within current address space, there no contiguous portion of memory big plenty serve wanted allocation. if have 100 blocks, each 4 mb large, not going help when need 1 5 mb block.
key points:
the info storage phone call “process memory” in sentiment best visualized massive file on disk. ram can seen simply performance optimization total amount of virtual memory programme consumes not hugely relevant performance "running out of ram" seldom results in “out of memory” error. instead of error, results in bad performance because total cost of fact storage on disk becomes relevant. c# memory-management out-of-memory
Comments
Post a Comment