5 registered members (AndrewAMD, ozgur, Ayumi, 2 invisible),
690
guests, and 10
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: C# wrapper - RELEASE
[Re: ventilator]
#317573
04/01/10 11:15
04/01/10 11:15
|
Joined: Dec 2002
Posts: 616 Austria
Stromausfall
OP
User
|
OP
User
Joined: Dec 2002
Posts: 616
Austria
|
i also tried that, but as soon, as the function returns -> the ref gets out of scope, the reference is lost ! Thus the ref is only valid within that function, but as soon as the function ends, the ref isn't valid anymore - and these special panel functions need a permanent reference to the variable
Last edited by Stromausfall; 04/01/10 11:17.
|
|
|
Re: C# wrapper - RELEASE
[Re: ventilator]
#317581
04/01/10 12:15
04/01/10 12:15
|
Joined: Dec 2002
Posts: 616 Austria
Stromausfall
OP
User
|
OP
User
Joined: Dec 2002
Posts: 616
Austria
|
the first problem is, that it's not able to save a ref to a variable afaik! and the next problem is, that the ref is only as long valid, as it is in the scope of the function ->
void dummy(ref int x)
{
only here x is valid !, as soon as the program jumps back to where dummy was called
from, x is invalid !
this works fine as long as we don't want to pass a permanent reference to a variable!
to make it permanent it would be necessary to stay as long in this scope, as we need the ref !
I tried that with Threads, but as mentioned - too much overhead and calling the function is
at least as ugly as the lambda approach ...
}
and one may also not use lambdas which use variables that are declared 'ref'!
|
|
|
Re: C# wrapper - RELEASE
[Re: Stromausfall]
#317599
04/01/10 13:05
04/01/10 13:05
|
Joined: Dec 2006
Posts: 434 UK,Terra, SolarSystem, Milky W...
pararealist
Senior Member
|
Senior Member
Joined: Dec 2006
Posts: 434
UK,Terra, SolarSystem, Milky W...
|
I was wondering if the two files var.h and var.cpp that are now in sdk could perhaps throw any light on the subject. It seems they have created a var class that is much better for programming in C++. I wonder if something similar could be done for C# ? This is just a suggestion.
A8.3x Commercial, AcknexWrapper and VS 2010 Express ○pararealist now.
|
|
|
Re: C# wrapper - RELEASE
[Re: pararealist]
#317601
04/01/10 13:18
04/01/10 13:18
|
Joined: May 2002
Posts: 7,441
ventilator
Senior Expert
|
Senior Expert
Joined: May 2002
Posts: 7,441
|
but fixed point variables are so old school. they shouldn't be used anymore. i think if you work with c# you should just use ints, floats,... and the wrapper should hide the necessary conversions. i would prefer if a8 gave up vars altogether. ... i really would like to experiment with all that c# reference/lambda/closure stuff but unfortunately i don't have much time at the moment. i am sure though that there is an elegant solution somewhere for this whole problem.
|
|
|
Re: C# wrapper - RELEASE
[Re: pararealist]
#317603
04/01/10 13:22
04/01/10 13:22
|
Joined: Dec 2002
Posts: 616 Austria
Stromausfall
OP
User
|
OP
User
Joined: Dec 2002
Posts: 616
Austria
|
@DJBMASTER nope boxing isn't useful, as you only box the value itself, not the variable ! thus if you pass a boxed variable and change it, the variable itself won't change !
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace dummyTest
{
class Program
{
static void changeVariableValue(object i)
{
int bla = (int)i; //unbox
bla++;
}
static void Main(string[] args)
{
int bla = 30;
changeVariableValue(bla);
Console.WriteLine(bla);
Console.ReadLine();
}
}
}
afaik the problem with ref is, as long as ref is active, the object can't be moved by the garbage collector (that doesn't imply deleting of the object, but just moving the object for better usage of memory). And like you said, when the function is out of scope, the variable in the object isn't fixed anymore and maybe somewhere else! You're right with stackalloc, that's how the current Var object handles this situation! @pararealist i had a quick look at these two files, but unfortunately their concept of operator overloading won't work in c#, as it's not possible to overload the equals (=) operator in c# @all what do you think about the mentioned method to use double instead of var and lambdas when necessaray (in the special panel functions) - is it superior to the current concept, or has someone a suggestion for another solution to this problem ? thanks in advance ^^
|
|
|
Re: C# wrapper - RELEASE
[Re: ventilator]
#317665
04/01/10 18:19
04/01/10 18:19
|
Joined: Oct 2004
Posts: 4,134 Netherlands
Joozey
Expert
|
Expert
Joined: Oct 2004
Posts: 4,134
Netherlands
|
Is there also a possibility to not make the wrapper unsafe, or implementations using the wrapper not bound to use unsafe code?
Last edited by Joozey; 04/01/10 18:20.
Click and join the 3dgs irc community! Room: #3dgs
|
|
|
|