Ejemplo n.º 1
0
        internal override DataBlockInfo ReadDataBlock()
        {
            DataBlockInfo blockInfo;

            blockInfo.dataBlock  = (byte *)Marshal.AllocHGlobal(DefaultBuffSize);
            blockInfo.itemHandle = (IntPtr)blockInfo.dataBlock;
            if (this.m_compressionScheme == DscCompressionScheme.None)
            {
                blockInfo.blockSize = this.m_dscStream.Read(blockInfo.dataBlock, DefaultBuffSize);
            }
            else
            {
                if (this.m_compressStream == null)
                {
                    if (this.m_compressionScheme == DscCompressionScheme.Gzip)
                    {
                        this.m_compressStream = new GZipStream(this.m_dscStream, CompressionMode.Decompress);
                    }
                    else
                    {
                        throw new DryadLinqException(HpcLinqErrorCode.UnknownCompressionScheme,
                                                     SR.UnknownCompressionScheme);
                    }
                }
                // YY: Made an extra copy here. Could do better.
                byte[] buffer = new byte[DefaultBuffSize];
                blockInfo.blockSize = this.m_compressStream.Read(buffer, 0, DefaultBuffSize);
                fixed(byte *pBuffer = buffer)
                {
                    HpcLinqUtil.memcpy(pBuffer, blockInfo.dataBlock, blockInfo.blockSize);
                }
            }

            return(blockInfo);
        }
Ejemplo n.º 2
0
        internal override unsafe bool WriteDataBlock(IntPtr itemHandle, Int32 numBytesToWrite)
        {
            byte *dataBlock = (byte *)itemHandle;

            if (this.m_compressionScheme == DscCompressionScheme.None)
            {
                Int32 numBytesWritten = 0;
                Int32 remainingBytes  = numBytesToWrite;

                while (remainingBytes > 0)
                {
                    Int32 *pNumBytesWritten = &numBytesWritten;
                    bool   success          = HpcLinqNative.WriteFile(this.m_fhandle,
                                                                      dataBlock,
                                                                      (UInt32)remainingBytes,
                                                                      (IntPtr)pNumBytesWritten,
                                                                      null);
                    if (!success)
                    {
                        throw new DryadLinqException(HpcLinqErrorCode.WriteFileError,
                                                     String.Format(SR.WriteFileError,
                                                                   Marshal.GetLastWin32Error()));
                    }

                    dataBlock      += numBytesWritten;
                    remainingBytes -= numBytesWritten;
                }
            }
            else
            {
                if (this.m_compressStream == null)
                {
                    if (this.m_compressionScheme == DscCompressionScheme.Gzip)
                    {
                        this.m_compressStream = new GZipStream(this.m_fstream,
                                                               CompressionMode.Compress);
                    }
                    else
                    {
                        throw new DryadLinqException(HpcLinqErrorCode.UnknownCompressionScheme,
                                                     SR.UnknownCompressionScheme);
                    }
                }
                // YY: Made an extra copy here. Could do better.
                byte[] buffer = new byte[numBytesToWrite];
                fixed(byte *pBuffer = buffer)
                {
                    HpcLinqUtil.memcpy(dataBlock, pBuffer, numBytesToWrite);
                }

                this.m_compressStream.Write(buffer, 0, numBytesToWrite);
            }
            return(true);
        }
Ejemplo n.º 3
0
        internal override unsafe DataBlockInfo ReadDataBlock()
        {
            DataBlockInfo blockInfo;

            blockInfo.dataBlock  = (byte *)Marshal.AllocHGlobal(DefaultBuffSize);
            blockInfo.itemHandle = (IntPtr)blockInfo.dataBlock;
            if (this.m_compressionScheme == DscCompressionScheme.None)
            {
                Int32 *pBlockSize = &blockInfo.blockSize;
                bool   success    = HpcLinqNative.ReadFile(this.m_fhandle,
                                                           blockInfo.dataBlock,
                                                           DefaultBuffSize,
                                                           (IntPtr)pBlockSize,
                                                           null);
                if (!success)
                {
                    throw new DryadLinqException(HpcLinqErrorCode.ReadFileError,
                                                 String.Format(SR.ReadFileError,
                                                               Marshal.GetLastWin32Error()));
                }
            }
            else
            {
                if (this.m_compressStream == null)
                {
                    if (this.m_compressionScheme == DscCompressionScheme.Gzip)
                    {
                        this.m_compressStream = new GZipStream(this.m_fstream,
                                                               CompressionMode.Decompress);
                    }
                    else
                    {
                        throw new DryadLinqException(HpcLinqErrorCode.UnknownCompressionScheme,
                                                     SR.UnknownCompressionScheme);
                    }
                }
                // YY: Made an extra copy here. Could do better.
                byte[] buffer = new byte[DefaultBuffSize];
                blockInfo.blockSize = this.m_compressStream.Read(buffer, 0, DefaultBuffSize);
                fixed(byte *pBuffer = buffer)
                {
                    HpcLinqUtil.memcpy(pBuffer, blockInfo.dataBlock, blockInfo.blockSize);
                }
            }

            return(blockInfo);
        }
Ejemplo n.º 4
0
        internal override unsafe bool WriteDataBlock(IntPtr itemHandle, Int32 numBytesToWrite)
        {
            byte *dataBlock = (byte *)itemHandle;

            if (this.m_compressionScheme == DscCompressionScheme.None)
            {
                Int32 numBytesWritten = 0;
                Int32 remainingBytes  = numBytesToWrite;

                while (remainingBytes > 0)
                {
                    numBytesWritten = this.m_dscStream.Write(dataBlock, 0, remainingBytes);
                    dataBlock      += numBytesWritten;
                    remainingBytes -= numBytesWritten;
                }
            }
            else
            {
                if (this.m_compressStream == null)
                {
                    if (this.m_compressionScheme == DscCompressionScheme.Gzip)
                    {
                        this.m_compressStream = new GZipStream(this.m_dscStream, CompressionMode.Compress);
                    }
                    else
                    {
                        throw new DryadLinqException(HpcLinqErrorCode.UnknownCompressionScheme,
                                                     SR.UnknownCompressionScheme);
                    }
                }
                // YY: Made an extra copy here. Could do better.
                byte[] buffer = new byte[numBytesToWrite];
                fixed(byte *pBuffer = buffer)
                {
                    HpcLinqUtil.memcpy(dataBlock, pBuffer, numBytesToWrite);
                }

                this.m_compressStream.Write(buffer, 0, numBytesToWrite);
            }
            return(true);
        }