SlideShare a Scribd company logo
C++ via C#
Egor Bogatov
@EgorBo
Calling C++ from C#. For what?
• Lovely IDE + R#
• Syntactic sugar
• nuget
Calling C++ from C#. How?
• C++/CLI
• COM
• [DllImport], [MethodImpl]
• IPC, Sockets,…
Calling C++ from C#. How?
• C++/CLI
• COM
• [DllImport], [MethodImpl]
• IPC, Sockets,…
UrhoSharp
• ~ 200 classes
• ~ 5000 methods
• Same FPS
• +10% memory
• C# for:
Windows
Mac OS
Android
iOS
tvOS
Urho3D API
class Node : public Animatable
{
public:
Node(Context* context);
void SetName(const String& name);
const String& GetName();
void SetPosition(const Vector3& position);
const Vector3& GetPosition();
void AddChild(Node* node, unsigned index = M_MAX_UNSIGNED);
void RemoveChild(Node* node);
};
public class Node : Animatable
{
public Node(Context context) { }
public string Name { get; set; }
public Vector3 Position { get; set; }
void AddChild(Node node, uint index = uint.MaxValue) { }
void RemoveChild(Node node) { }
}
Node.cpp
C++
C#
Urho3D API
class Node : public Animatable
{
public:
Node(Context* context);
void SetName(const String& name);
};
glue.cpp
Urho3D API
Node.cpp
C#
Node node = new Node(context);
node.SetName("foo");
Node* node = new Node(context_);
node->SetName("foo");
Urho3D APIvoid SetName(const String& name);
extern "C"
DllExport void Node_SetName (Node *target, const char * name){
target->SetName (Urho3D::String(name));
}
[DllImport ("mono-urho", …)]
static extern void Node_SetName (IntPtr handle, string name);
public void SetName (string name) { Node_SetName (handle, name);
Node.cppNode.h
binding.cpp
Node.cs
original API
generated
generated
Urho3D API
class Node : public Animatable
{
public:
Node(Context* context);
void SetName(const String& name);
};
DllExport void* Node_Node (Context * context) {
return new Node(context);
}
DllExport void Node_SetName (Node *target, const char * name) {
target->SetName (Urho3D::String(name));
}
public partial class Node : Animatable
{
private IntPtr handle;
[DllImport ("mono-urho")]
static extern IntPtr Node_Node (IntPtr context);
public Node (Context context) { handle = Node_Node (context.Handle); }
[DllImport ("mono-urho")]
static extern void Node_SetName (IntPtr handle, string name);
public void SetName (string name) { Node_SetName (handle, name);
Node.cppNode.h
binding.cpp
Node.cs
original API
generated
generated
Binding flow
Urho3D sources
(*.cpp, *.h)
Urho.pch
Generator (Binder)
binding.cpp *.cs
UrhoSharp.dll
Win: mono-urho.dll
Droid: libmono-urho.so
OSX: libmono-urho.dylib
iOS: urho.framework
nuget package
all-urho.cpp via clang
roslyn
• clang
• gcc
• msvc
clang.dll
Nrefactory.dll
PCL, Profile7
Object lifecycle
RefCounted:
• AddRef
• ReleaseRef
• RefsCount
• ~dctor
Node node = new Node(context)
1) Allocate a native object (Node* node = new Node)
scene.AddNode(node)
2) AddRef is called, callback to managed code
3) Managed code receives the callback, adds hard reference to node
scene.RemoveAll();
5) Managed code receives callback from native ~dctor,
removes reference. GC is now able to collect empty wrapper.
6) GC collects managed wrapper
Egor Bogatov
@EgorBo
github:
• UrhoSharp
• CppSharp

More Related Content

What's hot

C++11
C++11C++11
Summary of C++17 features
Summary of C++17 featuresSummary of C++17 features
Summary of C++17 features
Bartlomiej Filipek
 
CodiLime Tech Talk - Grzegorz Rozdzialik: What the java script
CodiLime Tech Talk - Grzegorz Rozdzialik: What the java scriptCodiLime Tech Talk - Grzegorz Rozdzialik: What the java script
CodiLime Tech Talk - Grzegorz Rozdzialik: What the java script
CodiLime
 
Why my Go program is slow?
Why my Go program is slow?Why my Go program is slow?
Why my Go program is slow?
Inada Naoki
 
2018 cosup-delete unused python code safely - english
2018 cosup-delete unused python code safely - english2018 cosup-delete unused python code safely - english
2018 cosup-delete unused python code safely - english
Jen Yee Hong
 
Basic c++ 11/14 for python programmers
Basic c++ 11/14 for python programmersBasic c++ 11/14 for python programmers
Basic c++ 11/14 for python programmers
Jen Yee Hong
 
C++ 11 Features
C++ 11 FeaturesC++ 11 Features
C++ 11 Features
Jan Rüegg
 
Permute
PermutePermute
Modern c++ (C++ 11/14)
Modern c++ (C++ 11/14)Modern c++ (C++ 11/14)
Modern c++ (C++ 11/14)
Geeks Anonymes
 
C++11
C++11C++11
C++11
C++11C++11
C++11
ppd1961
 
C++20 the small things - Timur Doumler
C++20 the small things - Timur DoumlerC++20 the small things - Timur Doumler
C++20 the small things - Timur Doumler
corehard_by
 
C++11 & C++14
C++11 & C++14C++11 & C++14
C++11 & C++14
CyberPlusIndia
 
Fun with Lambdas: C++14 Style (part 2)
Fun with Lambdas: C++14 Style (part 2)Fun with Lambdas: C++14 Style (part 2)
Fun with Lambdas: C++14 Style (part 2)
Sumant Tambe
 
C++ Programming - 11th Study
C++ Programming - 11th StudyC++ Programming - 11th Study
C++ Programming - 11th Study
Chris Ohk
 
High performance web programming with C++14
High performance web programming with C++14High performance web programming with C++14
High performance web programming with C++14
Matthieu Garrigues
 
C++11
C++11C++11
Lambda Expressions in C++
Lambda Expressions in C++Lambda Expressions in C++
Lambda Expressions in C++
Patrick Viafore
 
C++17 introduction - Meetup @EtixLabs
C++17 introduction - Meetup @EtixLabsC++17 introduction - Meetup @EtixLabs
C++17 introduction - Meetup @EtixLabs
Stephane Gleizes
 
Basic c++ programs
Basic c++ programsBasic c++ programs
Basic c++ programs
harman kaur
 

What's hot (20)

C++11
C++11C++11
C++11
 
Summary of C++17 features
Summary of C++17 featuresSummary of C++17 features
Summary of C++17 features
 
CodiLime Tech Talk - Grzegorz Rozdzialik: What the java script
CodiLime Tech Talk - Grzegorz Rozdzialik: What the java scriptCodiLime Tech Talk - Grzegorz Rozdzialik: What the java script
CodiLime Tech Talk - Grzegorz Rozdzialik: What the java script
 
Why my Go program is slow?
Why my Go program is slow?Why my Go program is slow?
Why my Go program is slow?
 
2018 cosup-delete unused python code safely - english
2018 cosup-delete unused python code safely - english2018 cosup-delete unused python code safely - english
2018 cosup-delete unused python code safely - english
 
Basic c++ 11/14 for python programmers
Basic c++ 11/14 for python programmersBasic c++ 11/14 for python programmers
Basic c++ 11/14 for python programmers
 
C++ 11 Features
C++ 11 FeaturesC++ 11 Features
C++ 11 Features
 
Permute
PermutePermute
Permute
 
Modern c++ (C++ 11/14)
Modern c++ (C++ 11/14)Modern c++ (C++ 11/14)
Modern c++ (C++ 11/14)
 
C++11
C++11C++11
C++11
 
C++11
C++11C++11
C++11
 
C++20 the small things - Timur Doumler
C++20 the small things - Timur DoumlerC++20 the small things - Timur Doumler
C++20 the small things - Timur Doumler
 
C++11 & C++14
C++11 & C++14C++11 & C++14
C++11 & C++14
 
Fun with Lambdas: C++14 Style (part 2)
Fun with Lambdas: C++14 Style (part 2)Fun with Lambdas: C++14 Style (part 2)
Fun with Lambdas: C++14 Style (part 2)
 
C++ Programming - 11th Study
C++ Programming - 11th StudyC++ Programming - 11th Study
C++ Programming - 11th Study
 
High performance web programming with C++14
High performance web programming with C++14High performance web programming with C++14
High performance web programming with C++14
 
C++11
C++11C++11
C++11
 
Lambda Expressions in C++
Lambda Expressions in C++Lambda Expressions in C++
Lambda Expressions in C++
 
C++17 introduction - Meetup @EtixLabs
C++17 introduction - Meetup @EtixLabsC++17 introduction - Meetup @EtixLabs
C++17 introduction - Meetup @EtixLabs
 
Basic c++ programs
Basic c++ programsBasic c++ programs
Basic c++ programs
 

Similar to C++ via C#

CBSE Question Paper Computer Science with C++ 2011
CBSE Question Paper Computer Science with C++ 2011CBSE Question Paper Computer Science with C++ 2011
CBSE Question Paper Computer Science with C++ 2011
Deepak Singh
 
Computer science-2010-cbse-question-paper
Computer science-2010-cbse-question-paperComputer science-2010-cbse-question-paper
Computer science-2010-cbse-question-paperDeepak Singh
 
Web2Day 2017 - Concilier DomainDriveDesign et API REST
Web2Day 2017 - Concilier DomainDriveDesign et API RESTWeb2Day 2017 - Concilier DomainDriveDesign et API REST
Web2Day 2017 - Concilier DomainDriveDesign et API REST
Nicolas Faugout
 
How to Write Node.js Module
How to Write Node.js ModuleHow to Write Node.js Module
How to Write Node.js Module
Fred Chien
 
Adding Love to an API (or How to Expose C++ in Unity)
Adding Love to an API (or How to Expose C++ in Unity)Adding Love to an API (or How to Expose C++ in Unity)
Adding Love to an API (or How to Expose C++ in Unity)
Unity Technologies
 
JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?
Doug Hawkins
 
Android and cpp
Android and cppAndroid and cpp
Android and cpp
Joan Puig Sanz
 
Objective-Cひとめぐり
Objective-CひとめぐりObjective-Cひとめぐり
Objective-Cひとめぐり
Kenji Kinukawa
 
ASP.NET core
ASP.NET coreASP.NET core
ASP.NET core
Ivan Porta
 
C++ amp on linux
C++ amp on linuxC++ amp on linux
C++ amp on linux
Miller Lee
 
Ruby meets Go
Ruby meets GoRuby meets Go
Cross Platform App Development with C++
Cross Platform App Development with C++Cross Platform App Development with C++
Cross Platform App Development with C++
Joan Puig Sanz
 
Lies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerLies Told By The Kotlin Compiler
Lies Told By The Kotlin Compiler
Garth Gilmour
 
Lies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerLies Told By The Kotlin Compiler
Lies Told By The Kotlin Compiler
Garth Gilmour
 
JVM code reading -- C2
JVM code reading -- C2JVM code reading -- C2
JVM code reading -- C2
ytoshima
 
Csdfsadf
CsdfsadfCsdfsadf
Csdfsadf
Atul Setu
 

Similar to C++ via C# (20)

CBSE Question Paper Computer Science with C++ 2011
CBSE Question Paper Computer Science with C++ 2011CBSE Question Paper Computer Science with C++ 2011
CBSE Question Paper Computer Science with C++ 2011
 
Computer science-2010-cbse-question-paper
Computer science-2010-cbse-question-paperComputer science-2010-cbse-question-paper
Computer science-2010-cbse-question-paper
 
Web2Day 2017 - Concilier DomainDriveDesign et API REST
Web2Day 2017 - Concilier DomainDriveDesign et API RESTWeb2Day 2017 - Concilier DomainDriveDesign et API REST
Web2Day 2017 - Concilier DomainDriveDesign et API REST
 
How to Write Node.js Module
How to Write Node.js ModuleHow to Write Node.js Module
How to Write Node.js Module
 
Adding Love to an API (or How to Expose C++ in Unity)
Adding Love to an API (or How to Expose C++ in Unity)Adding Love to an API (or How to Expose C++ in Unity)
Adding Love to an API (or How to Expose C++ in Unity)
 
JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?
 
Android and cpp
Android and cppAndroid and cpp
Android and cpp
 
DCOM Comparison
DCOM ComparisonDCOM Comparison
DCOM Comparison
 
Objective-Cひとめぐり
Objective-CひとめぐりObjective-Cひとめぐり
Objective-Cひとめぐり
 
ASP.NET core
ASP.NET coreASP.NET core
ASP.NET core
 
Sbaw091006
Sbaw091006Sbaw091006
Sbaw091006
 
C++ amp on linux
C++ amp on linuxC++ amp on linux
C++ amp on linux
 
Ruby meets Go
Ruby meets GoRuby meets Go
Ruby meets Go
 
Cross Platform App Development with C++
Cross Platform App Development with C++Cross Platform App Development with C++
Cross Platform App Development with C++
 
Lies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerLies Told By The Kotlin Compiler
Lies Told By The Kotlin Compiler
 
Lies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerLies Told By The Kotlin Compiler
Lies Told By The Kotlin Compiler
 
JVM code reading -- C2
JVM code reading -- C2JVM code reading -- C2
JVM code reading -- C2
 
Csdfsadf
CsdfsadfCsdfsadf
Csdfsadf
 
C
CC
C
 
C
CC
C
 

Recently uploaded

Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
Łukasz Chruściel
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
Deuglo Infosystem Pvt Ltd
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Mind IT Systems
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
TheSMSPoint
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
timtebeek1
 
Launch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in MinutesLaunch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in Minutes
Roshan Dwivedi
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
Ayan Halder
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
Alina Yurenko
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
lorraineandreiamcidl
 

Recently uploaded (20)

Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
 
Launch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in MinutesLaunch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in Minutes
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
 

C++ via C#

  • 1. C++ via C# Egor Bogatov @EgorBo
  • 2. Calling C++ from C#. For what? • Lovely IDE + R# • Syntactic sugar • nuget
  • 3. Calling C++ from C#. How? • C++/CLI • COM • [DllImport], [MethodImpl] • IPC, Sockets,…
  • 4. Calling C++ from C#. How? • C++/CLI • COM • [DllImport], [MethodImpl] • IPC, Sockets,…
  • 5. UrhoSharp • ~ 200 classes • ~ 5000 methods • Same FPS • +10% memory • C# for: Windows Mac OS Android iOS tvOS
  • 6. Urho3D API class Node : public Animatable { public: Node(Context* context); void SetName(const String& name); const String& GetName(); void SetPosition(const Vector3& position); const Vector3& GetPosition(); void AddChild(Node* node, unsigned index = M_MAX_UNSIGNED); void RemoveChild(Node* node); }; public class Node : Animatable { public Node(Context context) { } public string Name { get; set; } public Vector3 Position { get; set; } void AddChild(Node node, uint index = uint.MaxValue) { } void RemoveChild(Node node) { } } Node.cpp C++ C#
  • 7. Urho3D API class Node : public Animatable { public: Node(Context* context); void SetName(const String& name); }; glue.cpp
  • 8. Urho3D API Node.cpp C# Node node = new Node(context); node.SetName("foo"); Node* node = new Node(context_); node->SetName("foo");
  • 9. Urho3D APIvoid SetName(const String& name); extern "C" DllExport void Node_SetName (Node *target, const char * name){ target->SetName (Urho3D::String(name)); } [DllImport ("mono-urho", …)] static extern void Node_SetName (IntPtr handle, string name); public void SetName (string name) { Node_SetName (handle, name); Node.cppNode.h binding.cpp Node.cs original API generated generated
  • 10. Urho3D API class Node : public Animatable { public: Node(Context* context); void SetName(const String& name); }; DllExport void* Node_Node (Context * context) { return new Node(context); } DllExport void Node_SetName (Node *target, const char * name) { target->SetName (Urho3D::String(name)); } public partial class Node : Animatable { private IntPtr handle; [DllImport ("mono-urho")] static extern IntPtr Node_Node (IntPtr context); public Node (Context context) { handle = Node_Node (context.Handle); } [DllImport ("mono-urho")] static extern void Node_SetName (IntPtr handle, string name); public void SetName (string name) { Node_SetName (handle, name); Node.cppNode.h binding.cpp Node.cs original API generated generated
  • 11. Binding flow Urho3D sources (*.cpp, *.h) Urho.pch Generator (Binder) binding.cpp *.cs UrhoSharp.dll Win: mono-urho.dll Droid: libmono-urho.so OSX: libmono-urho.dylib iOS: urho.framework nuget package all-urho.cpp via clang roslyn • clang • gcc • msvc clang.dll Nrefactory.dll PCL, Profile7
  • 12. Object lifecycle RefCounted: • AddRef • ReleaseRef • RefsCount • ~dctor Node node = new Node(context) 1) Allocate a native object (Node* node = new Node) scene.AddNode(node) 2) AddRef is called, callback to managed code 3) Managed code receives the callback, adds hard reference to node scene.RemoveAll(); 5) Managed code receives callback from native ~dctor, removes reference. GC is now able to collect empty wrapper. 6) GC collects managed wrapper

Editor's Notes

  1. Add 2/3 circles aligned in a row on a separate slide.