Background and motivation
https://learn.microsoft.com/en-us/dotnet/api/system.buffer.blockcopy?view=net-10.0 cannot access dst array above 2 GB because the byte offset is passed as int.
Looking at the current implementation, it already extends the offset to nuint internally, so this should be an easy addition.
API Proposal
public class Buffer
{
public static void BlockCopy(Array src, int srcOffset, Array dst, long dstOffset, int count);
}
API Usage
// Read `a` from `BR`
void ReadWeights(BinaryReader BR, short[] a, int n)
{
const int bufSize = 4096;
byte[] buf = new byte[bufSize * 2];
for (int i = 0; i < n; i += bufSize) {
int m = Math.Min(n - i, bufSize);
if (BR.Read(buf, 0, m * 2) != m * 2)
throw new IOException("Truncated read");
#if false
for (int j = 0; j < m; j++)
a[i + j] = (short) (buf[j * 2] | buf[j * 2 + 1] << 8);
#else
Buffer.BlockCopy(buf, 0, a, i * 2L, m * 2);
#endif
}
}
Alternative Designs
nint or nuint - my experience with these is limited.
Risks
No response
Background and motivation
https://learn.microsoft.com/en-us/dotnet/api/system.buffer.blockcopy?view=net-10.0 cannot access
dstarray above 2 GB because the byte offset is passed asint.Looking at the current implementation, it already extends the offset to
nuintinternally, so this should be an easy addition.API Proposal
API Usage
Alternative Designs
nintornuint- my experience with these is limited.Risks
No response