示例#1
0
 /// <summary>
 /// Creates a new array of limbs initialized with <paramref name="values"/> in unmanaged memory.
 /// </summary>
 /// <param name="values">The values of the limbs.</param>
 /// <remarks>
 /// <para>
 /// If there is not enough 16-bit words to fill out the most significant limb, it is padded with zeroes.
 /// </para>
 /// <para>
 /// When done with the array, you must release the unmanaged memory by calling <see cref="gmp_lib.free(mp_ptr[])">free</see>.
 /// </para>
 /// </remarks>
 public mp_ptr(ushort[] values)
 {
     if (values == null)
     {
         throw new ArgumentNullException("values");
     }
     mp         = new mp_base();
     mp._size   = (2 * values.Length + IntPtr.Size - 1) / IntPtr.Size;
     mp.Pointer = gmp_lib.allocate((size_t)(mp._size * IntPtr.Size)).ToIntPtr();
     Marshal.Copy(new Int32[] { 0, 0 }, 0, (IntPtr)(mp.Pointer.ToInt64() + IntPtr.Size * (mp._size - 1)), IntPtr.Size >> 2);
     Marshal.Copy((short[])(object)values, 0, mp.Pointer, values.Length);
 }
示例#2
0
 /// <summary>
 /// Creates a new array of limbs initialized with <paramref name="values"/> in unmanaged memory.
 /// </summary>
 /// <param name="values">The values of the limbs.</param>
 /// <remarks>
 /// <para>
 /// If there is not enough bytes to fill out the most significant limb, it is padded with zeroes.
 /// </para>
 /// <para>
 /// When done with the array, you must release the unmanaged memory by calling <see cref="gmp_lib.free(mp_ptr[])">free</see>.
 /// </para>
 /// </remarks>
 public mp_ptr(byte[] values)
 {
     if (values == null)
     {
         throw new ArgumentNullException("values");
     }
     mp = new mp_base();
     if (values.GetLength(0) == 0)
     {
         mp._size   = 0;
         mp.Pointer = IntPtr.Zero;
     }
     else
     {
         mp._size   = (values.Length + IntPtr.Size - 1) / IntPtr.Size;
         mp.Pointer = gmp_lib.allocate((size_t)(mp._size * IntPtr.Size)).ToIntPtr();
         Marshal.Copy(new Int32[] { 0, 0 }, 0, (IntPtr)(mp.Pointer.ToInt64() + IntPtr.Size * (mp._size - 1)), IntPtr.Size >> 2);
         Marshal.Copy(values, 0, mp.Pointer, values.Length);
     }
 }
示例#3
0
 /// <summary>
 /// Creates new pointer to array of limbs at <paramref name="mp"/>.
 /// </summary>
 /// <param name="mp">Represents an array of limbs.</param>
 public mp_ptr(mp_base mp)
 {
     this.mp = mp;
 }