Free cookie consent management tool by TermsFeed Policy Generator

source: branches/thasling/DistributedGA/DistributedGA.Core/Util/ByteArrayWrapper.cs @ 14253

Last change on this file since 14253 was 14253, checked in by gkronber, 8 years ago

bugfixing (memory leaks)

File size: 828 bytes
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading;
6using System.Threading.Tasks;
7
8namespace DistributedGA.Core.Util {
9  public class ByteArrayWrapper {
10    public static int AliveCounter;
11    public static int AllocatedCounter;
12    public static int FreedCounter;
13
14    public static ByteArrayWrapper CreateByteArrayWrapper(byte[] arr) {
15      return new ByteArrayWrapper(arr);
16    }
17
18    public byte[] Array { get; private set; }
19
20    private ByteArrayWrapper(byte[] arr) {
21      Interlocked.Increment(ref AliveCounter);
22      Interlocked.Increment(ref AllocatedCounter);
23      this.Array = arr;
24    }
25
26    ~ByteArrayWrapper() {
27      Interlocked.Decrement(ref AliveCounter);
28      Interlocked.Increment(ref FreedCounter);
29    }
30  }
31}
Note: See TracBrowser for help on using the repository browser.