title: C#: Using a generic to create a pointer array
body: <p>Afternoon all,</p>
  
  <p>a little help if you please. In order to circumvent the 2Gb object limit in .NET I have made a class that allocates memory on the heap and this allows me to create arrays up to the limit of my free RAM. However, for ease of development (as it was a proof of concept) it was hard coded for longs. Now that it works I've been trying to alter the code to use generics so I can use the same code for multiple types.</p>
  
  <p>In allocating the memory and correctly index the array I need an array of pointers of the same type that the array will hold i.e. a long array needs <code>long*[] myLargeArray</code>. The problem is when I use generics this declaration becomes <code>T*[] myLargeArray</code>, which always produces the error <strong><em>'Cannot take the address of, get the size of, or declare a pointer to a managed type ('T')'</em></strong></p>
  
  <p>Thanks in advance.</p>
  
  <p>PS Before anyone asks, yes I really do need such large arrays.</p>
  
  <p>Code example for a 2D array:</p>
  
  <pre><code>
      LargeArray &lt;int&gt; myArray = new LargeArray&lt;int&gt;(x, y);
  
      public unsafe class LargeArray where T : struct
      {
          ...
          private T*[] tArr;
          ...
          public LargeArray(long sizeI, long sizeJ)
          {
              ...
              myLargeArray = new T*[sizeI];
              ...
          }
      }
  
  </code></pre>