Add function : MemCompare
BlitzMax Forums/BlitzMax Module Tweaks/Add function : MemCompare
| ||
| MemCompare function is usefull to compare memory blocks, ex : Matrix class, array with a Object, etc... in brl.blitz module : in blitz_memory.h, add int bbMemCompare( const void *src,const void *with,int size ); in blitz_memory.c, add
int bbMemCompare( const void *src,const void *with,int size ){
return memcmp( src,with,size );
}
in blitz.bmx, add Rem bbdoc: Compares the relation ship between the content of the memory blocks returns: A zero integer value if equal, a greater integer value if first @src byte value as greater than @with and less integer value if first @src byte value as less then @with. EndRem Function MemCompare%( src:Byte ptr,with:Byte Ptr,size )="bbMemCompare" in command line, recompile a brl.blitz module, and update doc with docmods. example:
Type Matrix
Field _00#,_01#,_02#,_03#
Field _10#,_11#,_12#,_13#
Field _20#,_21#,_22#,_23#
Field _30#,_31#,_32#,_33#
Method Compare%(with:Object)
Local T:Matrix = Matrix(with)
If (T <> Null) Return MemCompare(Self, with , SizeOf(Matrix)
Return False
EndMethod
EndType
Local m1:Matrix = new Matrix
Local m2:Matrix = new Matrix
' Change attributes of matrix if you want testing MemCompare return value.
If Not(m1 = m2)
Print "m1 = m2"
Else
Print "m1 <> m2"
EndIf
For more informations, see a memcmp function from C function reference. |
| ||
| This would be a useful addition for the official module. |