Advertisement
c0001

Untitled

Jan 29th, 2020
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 0.89 KB | None | 0 0
  1. import std.stdio;
  2. import std.concurrency;
  3. import core.memory;
  4. import core.thread;
  5.  
  6. version=ManyAllocations;
  7.  
  8. version(ManyAllocations)
  9.     alias ulong testtype;
  10. else
  11.     alias uint testtype;
  12.  
  13. void client() {
  14.     for (bool running = true; running; ) {
  15.         receive(
  16.             (testtype a, testtype b, testtype c, testtype d) {
  17.             },
  18.             (OwnerTerminated t) {
  19.                 running = false;
  20.             }
  21.         );
  22.     }
  23. }
  24.  
  25. void main() {
  26.     auto tid = spawn(&client);
  27.     int allocations = 0;
  28.     auto totalBeforeMem = GC.stats.usedSize;
  29.  
  30.     foreach (i; 0 .. 100) {
  31.         Thread.sleep(usecs(100));
  32.  
  33.         auto beforeMem = GC.stats.usedSize;
  34.         tid.send(cast(testtype) 1, cast(testtype) 2, cast(testtype) 3, cast(testtype) 4);
  35.         auto afterMem = GC.stats.usedSize;
  36.         if (afterMem > beforeMem)
  37.             allocations++;
  38.     }
  39.     auto totalAfterMem = GC.stats.usedSize;
  40.     writefln("allocations: %d  bytes: %d", allocations, totalAfterMem - totalBeforeMem);
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement