-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is c++/cli gcnew "magic" from a CPython module possible? Or a module written in C# ? #251
Comments
Look at the buffer protocol implementation. I think this is what you're looking for That works for numpy, I haven't tried pandas, but it'll work with It won't get any faster than this, we're effectively casting the internal memory structure of the Python object into a C# Span (which is a fancy pointer) |
Checkout this demo function https://github.com/tonybaloney/CSnakes/blob/main/samples/simple/QuickConsoleTest/Program.cs#L54-L74 for an example |
Thanks, using buffers is a brilliant idea, I just have to get my "head around" it and find out what the limits are to such an approach while using it with dotnet/CLR and WinUI3 ... With the idea behind your CSnakes it seems to be possible to allocate the needed chunk of memory on the python side, fill it as a struct which could be used from C#, having an interface/class code generated, compile that at runtime if needed and use that as a super efficiant bridge from python to C#. If it is possible to construct dotnet string using pointers to UTF-16 data there would be two options: the "clean" one by putting the UTF-16 data into python buffer too or giving pointers directly to the PyString UTF-16 data and dealing with those reference counts on the C# side too. Hope I find out what is possible. For me CSnakes looks like the most usefull and performant dotnet bridge there is today. |
The idea is to use existing C# and/or new highly specialized classes written in c++ to move data from CPython to C# . Why waste time and heap by wrapping if the c# object can be created directly from within a highly specialized CPython module?
If that is possible - could someone for noobs like me provide a Visual Studio code project?
In the projects I've written the count of objects from passed Python to C# was about 100-1000 times more than the other way... this time it might be 50000 X upwards. As it will be a WinUI3 application accessing wrapped CPython object attributes would be death by roundtrips... . Last resort would be using a shared SQLite instance on both sides...
The text was updated successfully, but these errors were encountered: