Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 9th, 2012  |  syntax: None  |  size: 0.88 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Does the D garbage collector work?
  2. import core.memory, std.stdio;
  3.  
  4. extern(Windows) int GlobalMemoryStatusEx(ref MEMORYSTATUSEX lpBuffer);
  5.  
  6. struct MEMORYSTATUSEX
  7. {
  8.     uint Length, MemoryLoad;
  9.     ulong TotalPhys, AvailPhys, TotalPageFile, AvailPageFile;
  10.     ulong TotalVirtual, AvailVirtual, AvailExtendedVirtual;
  11. }
  12.  
  13. void testA(size_t count)
  14. {
  15.     size_t[] a;
  16.     foreach (i; 0 .. count)
  17.         a ~= i;
  18.     //delete a;
  19. }
  20.  
  21. void main()
  22. {
  23.     MEMORYSTATUSEX ms;
  24.     ms.Length = ms.sizeof;
  25.  
  26.     foreach (i; 0 .. 32)
  27.     {
  28.         testA(16 << 20);
  29.         GlobalMemoryStatusEx(ms);
  30.         stderr.writefln("AvailPhys: %s MiB", ms.AvailPhys >>> 20);
  31.     }
  32. }
  33.        
  34. AvailPhys: 3711 MiB
  35. AvailPhys: 3365 MiB
  36. AvailPhys: 3061 MiB
  37. AvailPhys: 2747 MiB
  38. AvailPhys: 2458 MiB
  39. core.exception.OutOfMemoryError
  40.        
  41. AvailPhys: 3714 MiB
  42. AvailPhys: 3702 MiB
  43. AvailPhys: 3701 MiB
  44. AvailPhys: 3702 MiB
  45. AvailPhys: 3702 MiB
  46. ...