Gamestudio Links
Zorro Links
Newest Posts
MT5 bridge not working on MT5 v. 5 build 4160
by EternallyCurious. 04/25/24 20:49
Data from CSV not parsed correctly
by EternallyCurious. 04/25/24 10:20
Trading Journey
by howardR. 04/24/24 20:04
M1 Oversampling
by Petra. 04/24/24 10:34
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 827 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mega_Rod, EternallyCurious, howardR, 11honza11, ccorrea
19048 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 26 of 32 1 2 24 25 26 27 28 31 32
Re: C# wrapper - RELEASE [Re: Stromausfall] #317569
04/01/10 10:51
04/01/10 10:51
Joined: May 2002
Posts: 7,441
ventilator Offline
Senior Expert
ventilator  Offline
Senior Expert

Joined: May 2002
Posts: 7,441
thanks for your examples. laugh

wouldn't it also be possible to do a solution without lambdas but simply with "ref" and an array with all the vars and refs that get updated each frame?


Re: C# wrapper - RELEASE [Re: ventilator] #317573
04/01/10 11:15
04/01/10 11:15
Joined: Dec 2002
Posts: 616
Austria
Stromausfall Offline OP
User
Stromausfall  Offline 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 smirk

Last edited by Stromausfall; 04/01/10 11:17.

get the C# wrapper:
for A7.85.4 and A8.30.4, Version 2.3.9
at http://acknexwrapper2.matthias-auer.net/ or visit the thread
Re: C# wrapper - RELEASE [Re: Stromausfall] #317578
04/01/10 11:44
04/01/10 11:44
Joined: May 2002
Posts: 7,441
ventilator Offline
Senior Expert
ventilator  Offline
Senior Expert

Joined: May 2002
Posts: 7,441
but don't you store the ref in the array together with the corresponding var? then it shouldn't get lost?

Re: C# wrapper - RELEASE [Re: ventilator] #317581
04/01/10 12:15
04/01/10 12:15
Joined: Dec 2002
Posts: 616
Austria
Stromausfall Offline OP
User
Stromausfall  Offline 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 ->

Code:
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'!


get the C# wrapper:
for A7.85.4 and A8.30.4, Version 2.3.9
at http://acknexwrapper2.matthias-auer.net/ or visit the thread
Re: C# wrapper - RELEASE [Re: Stromausfall] #317597
04/01/10 13:00
04/01/10 13:00
Joined: Nov 2007
Posts: 1,143
United Kingdom
DJBMASTER Offline
Serious User
DJBMASTER  Offline
Serious User

Joined: Nov 2007
Posts: 1,143
United Kingdom
Does boxing the variable to System.Object help?

Also, I guess the problem with losing the reference is because when the function ends, the variable is marked for garbage collection.

You could use a 'fixed' block to pin the var in memory, although I'm not sure if this remains after the function is ended.

Additionally you can allocate memory using 'stackalloc' in an unsafe block, which means the GC wont touch it.

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 Offline
Senior Member
pararealist  Offline
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 Offline
Senior Expert
ventilator  Offline
Senior Expert

Joined: May 2002
Posts: 7,441
but fixed point variables are so old school. laugh 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. tongue

...
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 Offline OP
User
Stromausfall  Offline 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 !

Code:
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# frown


@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 ^^


get the C# wrapper:
for A7.85.4 and A8.30.4, Version 2.3.9
at http://acknexwrapper2.matthias-auer.net/ or visit the thread
Re: C# wrapper - RELEASE [Re: Stromausfall] #317642
04/01/10 16:48
04/01/10 16:48
Joined: May 2002
Posts: 7,441
ventilator Offline
Senior Expert
ventilator  Offline
Senior Expert

Joined: May 2002
Posts: 7,441
hm...

Code:
using System;

namespace AnonymousMethod
{
	delegate int Func();
	
	class Program
	{
		static Func[] funcArr = new Func[10];

		static void setPanelVariable(int i, Func f)
		{
			funcArr[i] = f;
		}

		static void Main(string[] args)
		{
			int i1 = 10;
			int i2 = 20;
			int i3 = 30;
			
			setPanelVariable(0, () => i1);
			setPanelVariable(1, () => i2);
			setPanelVariable(2, () => i3);
			
			for (int i = 0; i < 3; i++)
			{
				Console.WriteLine(funcArr[i]());
			}

			i1 = 111;
			i2 = 121;
			i3 = 131;
			
			for (int i = 0; i < 3; i++)
			{
				Console.WriteLine(funcArr[i]());
			}
			
			Console.ReadLine();
		}
	}
}

this seems to work fine. shouldn't this be useable nicely for panel variables? looks very similar to what i did in python but maybe i am misunderstanding something. i am no c# expert. laugh

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 Offline
Expert
Joozey  Offline
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
Page 26 of 32 1 2 24 25 26 27 28 31 32

Moderated by  TWO 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1