public static void Int32ToBytes(Int32 x, LongByteArray resultbuf, long bufoffset) { resultbuf[bufoffset + 0] = (byte)x; resultbuf[bufoffset + 1] = (byte)((UInt32)x >> 8); resultbuf[bufoffset + 2] = (byte)((UInt32)x >> 16); resultbuf[bufoffset + 3] = (byte)((UInt32)x >> 24); }
public static Int32 BytesToInt32(LongByteArray x, long offset) { Int32 result = 0; result |= x[offset + 0]; result |= (Int32)((UInt32)x[offset + 1] << 8); result |= (Int32)((UInt32)x[offset + 2] << 16); result |= (Int32)((UInt32)x[offset + 3] << 24); return(result); }
public static void Int64ToBytes(Int64 x, LongByteArray resultbuf, long bufoffset) { resultbuf[bufoffset + 0] = (byte)x; resultbuf[bufoffset + 1] = (byte)((UInt64)x >> 8); resultbuf[bufoffset + 2] = (byte)((UInt64)x >> 16); resultbuf[bufoffset + 3] = (byte)((UInt64)x >> 24); resultbuf[bufoffset + 4] = (byte)((UInt64)x >> 32); resultbuf[bufoffset + 5] = (byte)((UInt64)x >> 40); resultbuf[bufoffset + 6] = (byte)((UInt64)x >> 48); resultbuf[bufoffset + 7] = (byte)((UInt64)x >> 56); }
public static Int64 BytesToInt64(LongByteArray x, long offset) { Int64 result = 0; result |= x[offset + 0]; result |= (Int64)((UInt64)x[offset + 1] << 8); result |= (Int64)((UInt64)x[offset + 2] << 16); result |= (Int64)((UInt64)x[offset + 3] << 24); result |= (Int64)((UInt64)x[offset + 4] << 32); result |= (Int64)((UInt64)x[offset + 5] << 40); result |= (Int64)((UInt64)x[offset + 6] << 48); result |= (Int64)((UInt64)x[offset + 7] << 56); return(result); }
internal void slavethreadproc() { try { unsafe { byte *com = (byte *)pview; LongByteArray block = parent.block; long offset = 0; int length = 0; for (; ;) { if (!ewh.WaitOne(1000, true)) { if (parent.mainproc.WaitForExit(1)) { //throw new SlaveMemoryException("Slave process exiting because main process exited"); break; } continue; } byte action = com[0]; switch (action) { case 1: // Read case 3: // Batch read { byte *comnext = com; for (; ;) { offset = SlaveMemory.BytesToInt64(comnext, 1); length = SlaveMemory.BytesToInt32(comnext, 1 + 8); int pos = 1 + 8 + 4; long stop = offset + length; if (stop > block.LongLength) { throw new SlaveMemoryException("Read out of bounds (offset=" + offset.ToString() + ";length=" + length.ToString() + ")"); } if (length > parent.packetsize) { throw new SlaveMemoryException("Read out of bounds (length>packetsize; length=" + length.ToString() + ")"); } while (offset < stop) { comnext[pos++] = block[offset++]; } if (3 == action) { comnext += 1 + 8 + 4 + length; if (action == comnext[0]) { continue; } } break; } com[0] = 255; // Done! if (parent.usereturnevent) { signalreturnevent(); } } break; case 2: // Write case 4: // Batch write { byte *comnext = com; for (; ;) { offset = SlaveMemory.BytesToInt64(comnext, 1); length = SlaveMemory.BytesToInt32(comnext, 1 + 8); int pos = 1 + 8 + 4; long stop = offset + length; if (stop > block.LongLength) { throw new SlaveMemoryException("Write out of bounds (offset=" + offset.ToString() + ";length=" + length.ToString() + ")"); } if (length > parent.packetsize) { throw new SlaveMemoryException("Write out of bounds (length>packetsize; length=" + length.ToString() + ")"); } while (offset < stop) { block[offset++] = comnext[pos++]; } if (4 == action) { comnext += 1 + 8 + 4 + length; if (action == comnext[0]) { continue; } } break; } com[0] = 255; // Done! if (parent.usereturnevent) { signalreturnevent(); } } break; case 0: // Exit com[0] = 255; // Done. if (parent.usereturnevent) { signalreturnevent(); } return; // ! } } } } catch (Exception e) { if (null != parent.slavethreadprocexception) { //e.InnerException = parent.slavethreadprocexception; //parent.slavethreadprocexception = e; } else { parent.slavethreadprocexception = e; } } }
public TwoDInt32(long x, long y) { btable = new LongByteArray((x * y) << 2); rowsize = y; }
public OneDInt64(long numelements) { btable = new LongByteArray(numelements << 3); }
public OneDInt32(long numelements) { btable = new LongByteArray(numelements << 2); }
public static Int64 BytesToInt64(LongByteArray x) { return(BytesToInt64(x, 0)); }
public static Int32 BytesToInt32(LongByteArray x) { return(BytesToInt32(x, 0)); }