[vtkusers] c# port of VTK

Andy Somogyi endre-somogyi at comcast.net
Tue Aug 3 03:51:34 EDT 2004


Sean McInerney wrote:
> Andy,
> 
>   My apologies if I came across as kind of a buzz kill. It sounds like 
> an interesting project. I'm mostly a C++ and Unix guy ... so take my 
> perspective with a grain of salt when it comes to C# and windows ;-)

Thats OK, I'm really looking at what kind of ideas people have when it comes
to a project like this.

I've been doing c++ for a long time (too long) and IMO, the language has a lot of
'issues'. I'm a Linux / Java guy at work, and while I think Java has a great deal
of improvments over c++, there are also a lot of issues with Java.

IMO, c# addresses almost all of these issues. c# is also very cross platform,
thanks to mono and gnu.net.

I think the port is a fairly large project, but certainly not impossible, I've
worked on much larger projects. Currently, I have almost enough classes ported
over to compile and run the first tutorial project (the one with the cone source).


So anyway, the direction I think I will go is that all methods that took a
'double x[3]' param on the c++ side will take a 'Vector3*' param on the c# port.
Remeber that a 'Vector3' struct is just a group of 3 doubles, so an array can also
be cast as a 'Vector3*'. Also, a 'Vector3' struct has the [] array index operator
overloaded, so a user can treat it (syntacally) as an array of length 3.

As soon as I get further along, I'll start checking stuff into CVS on sourceforge.

> 
> -Sean
> 
> Lars Overgaard wrote:
> 
>> Hi Andy,
>>
>> I will stay out of the discussion of why you should do (or not do) your
>> project and just answer your initial question.
>>
>> I have experienced the huge overhead introduced by garbage collection
>> and
>> managed code. I write embedded applications and need both speed and
>> (close to)
>> real-time response.
>>
>> My preference would definitely be choice no. 3: use a 'Vector3' value
>> type.
>> I wouldn't hardly notice the slightly changed syntax - and the
>> alternative
>> choices would simply kill my applications.
>>
>> So, Andy, I encourage you to continue your interesting project using a
>> 'Vector3' value type.
>>
>> Good luck! Please let us know how your work is progressing.
>>
>> Best regards,
>>
>> Lars Overgaard
>> Software Engineer, Ph.D.
>> MIKROFYN A/S
>> * E-mail: lov at mikrofyn.com
>> : Web:     www.mikrofyn.com
>> ( Phone: +45 66170784
>> ( Direct: +45 63170510
>> h Fax:     +45 66170785
>>  
>>
>>
>> -----Oprindelig meddelelse-----
>> Fra: vtkusers-bounces at vtk.org [mailto:vtkusers-bounces at vtk.org] På vegne
>> af Andy Somogyi
>> Sendt: 2. august 2004 02:35
>> Til: vtkusers at vtk.org
>> Emne: [vtkusers] c# port of VTK
>>
>>
>> Hello VTK users
>>
>> I am in the process of completly porting VTK (4.2) to c#.
>> As this is c#, it can be used nativly from any .net language.
>>
>> When finished, it will be freely availble under the existing VTL
>> lisence.
>>
>> My question is this:
>>
>> The c++ version of VTK uses length 3 arrays to represent a vector in 3
>> space. This is fine in c++ because you can create arrays on the stack.
>>
>> It is not possible to create a managed array in c# on the stack, they
>> are allways heap allocated and garbage collected. So using a large
>> number of managed arrays, or creating large numbers of transitory arrays
>> is very inefficient.
>>
>> The use of a 'value type' or a 'struct' in other words is far more
>> effcient when large numbers of objects are involved as they are created
>> on the stack and are not garbage collected.
>>
>> I have thought about using a raw double pointer (double*) instead of an
>> managed array for all functions that use a vector (double[3]). This has
>> the advantage of being very fast, but on the other hand, it is highly
>> error prone, and a user of one of these functions must declare thier
>> method 'unsafe'. I would suspsct that this would discourage many users.
>>
>> There are many good vector and matrix classes avaible for .net, such as
>> the standard vector and matrix types that ship with directx 9.
>>
>> So my question to any perspective vtk.net users is would you prefer all
>> existing methods that currently accept a c++ style array (double[3])
>> accept the following in the new c# port:
>>
>> 1: managed array (new double[3])
>>      advantages:
>>      1.1 farmiliar syntax
>>      1.2 do not have to declare 'unsafe' code
>>      disadvanteges:
>>      1.2 very ineffcient both in terms of size and performance
>>
>> 2: unmanaged pointer (double*)
>>      advanteges:
>>      2.1 very effecient
>>      disadvantes:
>>      2.2 error prone
>>      2.3 need to pin a managed array or use 'stackalloc'
>>
>> 3: use a 'Vector3' value type
>>      advanteges
>>      3.1 very effcient
>>      3.2 very safe
>>      3.3 easy to convert to and from a 'double*'
>>      disadvantes:
>>      3.3 introduces unfarmiliair syntax
>>
>> Any ides or oppinions would be greatly appcieated
>>
>> thanks
>>
> 
> 




More information about the vtkusers mailing list