[Mono-dev] [PATCH] Make DateTime binary compatible with .NET

Jonathan Hseu vomjom at vomjom.net
Fri Nov 6 09:53:12 EST 2009


I previously discussed this patch on the mono IRC channel.

Motivation:

1. The current DateTime implementation is not binary compatible (with
BinaryFormatter) with .NET's DateTime.  There are many bugs on the tracker
related to this issue:

https://bugzilla.novell.com/show_bug.cgi?id=321869
https://bugzilla.novell.com/show_bug.cgi?id=325067
https://bugzilla.novell.com/show_bug.cgi?id=360429

My patch fixes this issue.  With BinaryFormatter, I serialized several
DateTimes (with different DateTimeKinds) from Visual Studio and was able to
successfully load them after the patch and tested that they were equivalent.

2. The current DateTime takes up 16 bytes.  The .NET one takes up 8 bytes.
 This is the primary reason for the above incompatibility.  Mono's extra
field was a "DateTimeKind kind".  I simply removed that and used flag bits
on the ticks field to indicate the kind so as to be compatible with .NET.

The size difference is an issue for me, because I currently load 50 million
DateTime records into memory, and 50 million * 8 bytes extra == 400
megabytes extra RAM used.


Caveats:

This new DateTime is binary incompatible (again with BinaryFormatter) with
older versions of Mono.


Please look over the contents of the patch as I am very new to C#.  I
welcome any comments.

Thanks,
Jonathan Hseu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20091106/9ae25633/attachment-0001.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: NetCompatibleDateTime.patch
Type: application/octet-stream
Size: 12191 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20091106/9ae25633/attachment-0001.obj 


More information about the Mono-devel-list mailing list