Lichtblitz
Sorceror
Avoid "unsafe" operations in BinaryFileWriter
Original code is commented out:
Original code is commented out:
PHP:
public /*unsafe*/ override void Write( double value )
{
// May dupe; MODIFIED: new implementation since operation was unsafe
byte[] eightBytes = System.BitConverter.GetBytes( value );
for ( int i = 0; i < 8; i++ )
{
Write( eightBytes[i] );
}
/*
if( (m_Index + 8) > m_Buffer.Length )
Flush();
fixed( byte* pBuffer = m_Buffer )
*((double*)(pBuffer + m_Index)) = value;
m_Index += 8;
*/
}
public /*unsafe*/ override void Write( float value )
{
// May dupe; MODIFIED: new implementation since operation was unsafe
byte[] fourBytes = System.BitConverter.GetBytes( value );
for ( int i = 0; i < 4; i++ )
{
Write( fourBytes[i] );
}
/*
if ( (m_Index + 4) > BufferSize )
Flush();
fixed ( byte* pBuffer = m_Buffer )
*((float*)(&pBuffer[m_Index])) = value;
m_Index += 4;
*/
}