/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="type"></param> /// <param name="target"></param> /// <param name="buffer"></param> public void QueueArray <T>(RpcRequest type, string target, IArray <T> buffer) where T : struct { var headerSize = FastStructure.SizeOf <InteropMessageHeader>(); var elementSize = FastStructure.SizeOf <T>(); if (headerSize + elementSize * buffer.Length > messageProducer.NodeBufferSize) { throw new Exception($"Cannot queue {buffer.Length} elements of {typeof(T)} - will not fit in a single message"); } // Construct a header with metadata for the array var header = new InteropMessageHeader { type = type, length = buffer.MaxLength, index = buffer.Offset, count = buffer.Length }; // Remove any queued messages with the same outbound header RemoveQueuedMessage(target, ref header); InteropLogger.Debug($" QA-> {target}:{type:F}"); outboundQueue.Enqueue(new InteropMessage { target = target, header = header, producer = (tar, hdr, ptr) => { buffer.CopyTo(ptr, 0, buffer.Length); return(elementSize * buffer.Length); } }); }
public static T[] ToArray <T>(this IArray <T> self) { var r = new T[self.Count]; self.CopyTo(r); return(r); }
/// <summary> /// Core接続配列に指定した配列のデータを設定します。 /// </summary> /// <typeparam name="TElement">Spanに格納される要素の型</typeparam> /// <param name="obj">配列のもとになるCore接続用配列クラスのインスタンス</param> /// <param name="span">書き込み先の<see cref="Span{TElement}"/></param> /// <exception cref="ArgumentNullException"><paramref name="obj"/>がnull</exception> /// <exception cref="ArgumentException"><paramref name="span"/>の長さが<see cref="IArray{TElement}.Count"/>未満。</exception> internal static void CopyTo <TElement>(this IArray <TElement> obj, Span <TElement> span) where TElement : unmanaged { if (obj == null) { throw new ArgumentNullException(nameof(obj), "引数がnullです"); } if (obj.Count > span.Length) { throw new ArgumentException(nameof(span), $"Spanの長さが{obj.Count}未満です。"); } if (obj.Count == 0) { return; } unsafe { fixed(TElement *ptr = span) { obj.CopyTo(new IntPtr(ptr)); } } }
public static T[] ToArraySlice <T>(this IArray <T> self, int from, int count) { if (from < 0) { from = 0; } int n = from + count > self.Count ? self.Count - from : count; if (n <= 0) { return(new T[0]); } return(self.CopyTo(from, new T[n], 0, n)); }
/// <summary> /// このインスタンスと同じデータを持った<typeparamref name="TElement"/>型の配列の新しいインスタンスを生成する /// </summary> /// <typeparam name="TElement">配列に格納される要素の型</typeparam> /// <param name="obj">配列のもとになるCore接続用配列クラスのインスタンス</param> /// <exception cref="ArgumentNullException"><paramref name="obj"/>がnull</exception> /// <returns><paramref name="obj"/>と同じデータを持った配列</returns> public static TElement[] ToArray <TElement>(this IArray <TElement> obj) where TElement : unmanaged { if (obj == null) { throw new ArgumentNullException(nameof(obj), "引数がnullです"); } var array = new TElement[obj.Count]; unsafe { fixed(TElement *ptr = array) { obj.CopyTo(new IntPtr(ptr)); } } return(array); }
public static T[] CopyTo <T>(this IArray <T> self, T[] dest, int destIndex = 0) { return(self.CopyTo(0, dest, destIndex, self.Count)); }
public T[] CopyTo(int srcIndex, T[] dest, int destIndex, int len) { return(a.CopyTo(srcIndex, dest, destIndex, len)); }
/// <summary> /// Converts the IArray into a system array. /// </summary> public static T[] ToArray <T>(this IArray <T> self) { return(self.CopyTo(new T[self.Count])); }