Why is Matrix a heavyweight class derived from MarshalByRefObject instead of a lightweight struct?
Why is Matrix a heavyweight class derived from MarshalByRefObject instead of a lightweight struct?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
Matrixclass is actually a wrapper to an unmanaged structure which is manipulated by the GDI+ Flat API.That said, it’s common for the classes in the
System.Drawingnamespace to derive from theMarshalByRefObjectclass for the convenience of anIDisposableimplementation as well as get automatic marshaling across the application domain boundary when used in Remoting.This was more than likely done because most of the GDI functions (which most of the APIs that the Windows Forms controls rely on) will use the GDI matrix for transformations; using a lightweight, fully managed code structure would require translation of that structure across the managed/unmanaged boundary every time a method was called.
Compared to the cost of marshaling just the call and the handle, versus the call and the entire structure whenever you want to do operations on the matrix, it was probably decided that for performance reasons it was better to marshal the calls.