コード例 #1
0
        // This works for vectors of types with fixed size.
        // decimal is an exception because it is not supported by Buffer.BlockCopy.
        public static void WriteVector <T> (RCArray <byte> result, RCArray <T> array, int size)
        {
            int length = (int)array.Count * size;

            WriteScalarInt(result, array.Count);
            result.Resize(length, 0);
            Buffer.BlockCopy(array._source, 0, result._source, (int)result._count, length);
            result._count += length;
        }
コード例 #2
0
 public static void WriteVectorDecimal(RCArray <byte> result, RCArray <decimal> data)
 {
     WriteScalarInt(result, data.Count);
     result.Resize(data.Count * sizeof(decimal), 0);
     for (int i = 0; i < data.Count; ++i)
     {
         decimal val = data[i];
         // This is horrible because a new byte[8] gets allocated for every
         // element in this vector.  But Buffer.BlockCopy does not work on
         // decimal and I spent a silly amount of time googling for efficient
         // ways to get the bits out one byte at a time, but that effort failed.
         // I still think there is hope though.
         int[] bits = decimal.GetBits(val);
         Buffer.BlockCopy(
             bits,
             0,
             result._source,
             (int)result._count + i * sizeof(decimal),
             sizeof(decimal));
     }
     result._count += data.Count * sizeof(decimal);
 }