Good to the last drop.

WhatMeWorry kheaser at gmail.com
Thu Mar 31 19:44:23 UTC 2022


I run the program (at the bottom) and get, as expected, the 
run-time out of memory error:

PS C:\D\sandbox> .\Reserve.exe
   newCapacity = [              1]
   newCapacity = [              3]
   newCapacity = [              5]
                 o    o    o
   newCapacity = [    905,207,293]
   newCapacity = [    905,207,805]
   newCapacity = [    905,208,317]

core.exception.OutOfMemoryError at src\core\lifetime.d(126): Memory 
allocation failed


Is there a way to programmatically determine the exact maximum 
memory size available to the DRuntime’s array implementation?


import std.stdio;
import std.format;

void main()
{
     ulong[] big;
     size_t newCapacity;
     size_t oldCapacity;
	
     foreach(i; 0..ulong.max)
     {
         newCapacity = big.reserve(i);
         if(oldCapacity != newCapacity)
         {
             writeln("  newCapacity = ", format("[%15,3d]", 
newCapacity) );
             oldCapacity = newCapacity;
         }
     }
}





More information about the Digitalmars-d-learn mailing list