From bd169bc13e241cea63c984fb5c4c9a1605fb0d9d Mon Sep 17 00:00:00 2001 From: HyperSphereStudio <69430085+HyperSphereStudio@users.noreply.github.com> Date: Tue, 11 Jan 2022 19:59:04 -0500 Subject: [PATCH 1/2] Version 1.5 --- README.md | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 02d6d8f..180f32c 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,16 @@ int v = (int) Julia.Eval("2 * 2"); Julia.Exit(0); ``` +Struct Handling: +```csharp + + #You have to choices, allocate a struct or create a struct. + #Allocating directly sets the memory, creating will call a constructor of the struct + + var myAllocatedStruct = Julia.AllocStruct(JLType.JLRef, 3); //Will throw error + var myCreatedStuct = JLType.JLRef.Create(3); //Will call constructor +``` + Function Handling: ```csharp Julia.Init(); @@ -18,8 +28,38 @@ Function Handling: JLType willbeInt64 = fun.ParameterTypes[1]; JLType willBeInt32 = fun.ReturnType; - int resultWillBe4 = (int) fun.Invoke(2); - object willReturnNetBoxed4 = fun.Invoke(2).Value; + JLVal resultWillBe4 = fun.Invoke(2); + Julia.Exit(0); +``` + +Value Handling: +```csharp + //Auto alloc to Julia + var val = new JLVal(3); + + //Manual Type Unboxing + long netVal = val.UnboxInt64(); + + //Auto Unboxing + object newVal2 = val.Value; +``` + +Array Handling: +```csharp + Julia.Init(); + JLArray arr = Julia.Eval("[2, 3, 4]") + + //Unpack to .net + object[] o = arr.LinearNetUnPack(); + + //Make own array + var newArray = long[arr.Length]; + for(int i = 1; i < arr.Length; ++i) + newArray[i - 1] = (long) arr[i]; + + JLType elementType = arr.ElType; + + Julia.Exit(0); ``` Exception Handling: @@ -32,6 +72,37 @@ Exception Handling: ``` +Garbage Collection: +You are (at the current moment of this project) responsible for ensuring object safety on both .NET and Julia. When you make calls to either language, the GC could activate and invalidate the reference you hold in the other language unless you pin it! + +CSharp Garbage Collector Pinning: +```csharp + Julia.Init(); + JLArray myArr = new JLArray(JLType.Int64, 5); //Allocate Int64 array of length 5 + + var handle = myArr.Pin(); //Pin the Object + + //Stuff calling Julia Functions + + handle.Free(); //Optional, handle destructor will auto call it. This is in case you want it freed earlier + + Julia.Exit(0); +``` +Keep In mind that there is another way to pin Julia objects using Julia.PUSHGC() and Julia.POPGC(). (The Julian way) + + +Julia Garbage Collector Pinning: +```julia + myBasicType = SharpType("MyBasicType") + myBasicCon = SharpConstructor(myBasicType) + myBasicObj = myBasicCon() + handle = pin(myBasicObj) + + //Stuff calling Sharp Functions + + free(handle) //Will also auto free. You can also treat it like stream and put it in do end block +``` + .NET Interface From 4ca6161d2cafd17c9bae6083fc722bd683925153 Mon Sep 17 00:00:00 2001 From: HyperSphereStudio <69430085+HyperSphereStudio@users.noreply.github.com> Date: Tue, 11 Jan 2022 20:00:15 -0500 Subject: [PATCH 2/2] Version 1.5.0 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 180f32c..9146a60 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Julia.Exit(0); Struct Handling: ```csharp - #You have to choices, allocate a struct or create a struct. + #You have two choices, allocate a struct or create a struct. #Allocating directly sets the memory, creating will call a constructor of the struct var myAllocatedStruct = Julia.AllocStruct(JLType.JLRef, 3); //Will throw error @@ -98,9 +98,9 @@ Julia Garbage Collector Pinning: myBasicObj = myBasicCon() handle = pin(myBasicObj) - //Stuff calling Sharp Functions + #Stuff calling Sharp Functions - free(handle) //Will also auto free. You can also treat it like stream and put it in do end block + free(handle) #Will also auto free. You can also treat it like stream and put it in do end block ```