@ -21,29 +21,46 @@ namespace ImGuiNET
public void Resize ( int newSize )
public void Resize ( int newSize )
{
{
Clear Buffer( ) ;
FreeNative Buffer( ) ;
CreateBuffer ( newSize ) ;
CreateBuffer ( newSize ) ;
}
}
private void CreateBuffer ( int size )
private unsafe void CreateBuffer ( int size )
{
{
Buffer = Marshal . AllocHGlobal ( size ) ;
Buffer = Marshal . AllocHGlobal ( size ) ;
Length = Length ;
Length = ( uint ) size ;
ClearData ( ) ;
}
}
private void ClearBuffer ( )
public unsafe void ClearData ( )
{
{
Marshal . FreeHGlobal ( Buffer ) ;
byte * ptr = ( byte * ) Buffer . ToPointer ( ) ;
Buffer = IntPtr . Zero ;
for ( int i = 0 ; i < Length ; i + + )
Length = 0 ;
{
ptr [ i ] = 0 ;
}
}
}
public void Dispose ( )
public void Dispose ( )
{
{
if ( Buffer ! = IntPtr . Zero )
if ( Buffer ! = IntPtr . Zero )
{
{
Clear Buffer( ) ;
FreeNative Buffer( ) ;
}
}
}
}
private void FreeNativeBuffer ( )
{
Marshal . FreeHGlobal ( Buffer ) ;
Buffer = IntPtr . Zero ;
Length = 0 ;
}
public string GetString ( )
{
return Marshal . PtrToStringAnsi ( Buffer ) ;
}
public override string ToString ( ) = > GetString ( ) ;
}
}
}
}