|
Enhanced C#
Loyc library documentation
|
A data-reading object returned by IScannable{T} implementations. This interface is used for reading data, similar to IEnumerator{T}, but it reads blocks of data instead of single items. This can improve performance by reducing the number of interface calls necessary to scan a collection. More...
A data-reading object returned by IScannable{T} implementations. This interface is used for reading data, similar to IEnumerator{T}, but it reads blocks of data instead of single items. This can improve performance by reducing the number of interface calls necessary to scan a collection.
Properties | |
| bool | CanScanBackward [get] |
Returns true if the skip parameter is allowed to be negative when calling Read(int, int, ref Memory{T}). More... | |
Public Member Functions | |
| ReadOnlyMemory< T > | Read (int skip, int minLength, ref Memory< T > buffer) |
Jumps forward in the input by the specified amount, and reads a chunk of data at the new location (without skipping past it, i.e. it's possible to read the same data again by calling this method again with skip: 0). The precise chunk size is chosen by the scanner. More... | |
| ReadOnlyMemory<T> Loyc.Collections.IScanner< T >.Read | ( | int | skip, |
| int | minLength, | ||
| ref Memory< T > | buffer | ||
| ) |
Jumps forward in the input by the specified amount, and reads a chunk of data at the new location (without skipping past it, i.e. it's possible to read the same data again by calling this method again with skip: 0). The precise chunk size is chosen by the scanner.
| skip | Amount of data to advance past in the input. If the caller wants to have access to each data item in the sequence exactly once, this parameter should be 0 the first time it calls this method, and mem.Length (where mem is the previous return value of this method) each time afterward. |
| minLength | Minimum block size. The scanner must return a memory block with a Length at least this high, unless there are not enough remaining items in the collection or data stream to achieve this. If minLength is zero or negative (e.g. -1), the scanner must return at least one item, and should choose whatever amount is optimal for the scanner. |
Caution: do not use an excessive amount such as int.MaxValue for this parameter; doing so is harmless in some implementations (which just return the remainder of the list) but causes OutOfMemoryException in others, such as streams that don't know their own length and always allocate a memory block of at least the requested size.
| buffer | If the scanner cannot naturally offer a block as large as requested, it may need a temporary storage area in which to combine multiple blocks. If so, the method can use a buffer provided by the caller in this parameter, if that buffer is large enough. If the caller provides a memory block that is smaller than minLength, and if the scanner also needs to allocate a buffer, the scanner allocates a new buffer and returns it in this parameter. |
If the caller doesn't need to re-use or re-read old buffers, it should simply initialize a variable to the default value and pass the same variable into this parameter every time it calls this method. If, on the other hand, the caller wants to preserve the contents of an old buffer, it should send a new empty buffer in this parameter so that this method won't overwrite the old one.
Note: IScanner{T} implementations are allowed to ignore this parameter. If you send a very large buffer, the scanner may or may not decide to use all of it.
| ArgumentException | skip was negative, and backward scanning is not supported or the caller tried to skip backward beyond the beginning of the sequence. |
The caller can force the entire sequence to be read into a single contiguous buffer by using minLength = int.MaxValue. On the other hand, if you want the scanner to use the size it deems optimal, set minLength = -1.
Implemented in Loyc.Collections.Impl.InternalList.Scanner< T >.
|
get |
Returns true if the skip parameter is allowed to be negative when calling Read(int, int, ref Memory{T}).
1.8.7