bflattened / bflat

C# as you know it but with Go-inspired tooling (small, selfcontained, and native executables)
GNU Affero General Public License v3.0
3.63k stars 104 forks source link

Which language features not available in the Zero stdlib? #149

Closed ghost closed 8 months ago

ghost commented 8 months ago

I'm interested in this stdlib. But the only thing I know is it doesn't have a GC. The thread asking about memory management #138 is too few in the details. The answer by Dwedit is to use HeapAlloc/HeapFree on raw pointers. But, how?

Btw, I did a quick Google search. HeapAlloc/HeapFree are Windows-only. What if I want to develop for Linux? Or, what if I want to do it in a cross platform way so it will work everywhere?

Please elaborate. Thank you.

MichalStrehovsky commented 8 months ago

Implementation of zerolib is here: https://github.com/bflattened/bflat/tree/master/src/zerolib

It's the best docs. Sorry, I don't have time to write better docs for this.

You can p/invoke into libc (use malloc/free, for example). These APIs are pretty universal and available on both Linux and Windows.

ghost commented 8 months ago

You can p/invoke into libc (use malloc/free, for example). These APIs are pretty universal and available on both Linux and Windows.

Is there a ready to use definition or I have to write the p/invoke definition myself? For example, I found both HeapAlloc/HeapFree in WindowsAPIs.txt. Where is the C# definition for them? Or, do I need to write the p/invoke definition myself?

lucabol commented 8 months ago

You have to write it yourself (or google for it, or ask github copilot to write them for you).

ghost commented 8 months ago

From the table on https://flattened.net/, the Zero stdlib only has Marshalling-less p/invoke. Could you elaborate more about this? How could I handle the struct layout and the fixed size C string members in the struct?

lucabol commented 8 months ago

I suspect that you are limited by what described here: https://learn.microsoft.com/en-us/dotnet/standard/native-interop/disabled-marshalling

ghost commented 8 months ago

Do I need to write the p/invoke definition myself to use the functions in WindowsAPIs.txt? Or is there something ready to use?

lucabol commented 8 months ago

You have to write it yourself.

ghost commented 8 months ago

Console.Write can only write a single character? I tried to write an integer and it failed to compile. Only Console.WriteLine support writing a string and has an overload to write an integer.

lucabol commented 8 months ago

zerolib has just the code needed to make the examples run. If you need anything else, you have to write it yourself. If you have questions on what is implemented and what isn't, you can look at the code. Either it is there or not (most likely not).

ghost commented 8 months ago

zerolib has just the code needed to make the examples run. If you need anything else, you have to write it yourself. If you have questions on what is implemented and what isn't, you can look at the code. Either it is there or not (most likely not).

Can I ask for more methods of the standard runtime to be added to zerolib? Writing these methods myself is not an option.

lucabol commented 8 months ago

@MichalStrehovsky is the owner and decide everything. I am just a passerby trying to help a fellow user :-)

My own take is that zerolib is an experiment/gift from Michal for people who want to play around, try out new things and are willing to tolerate rough edges. I don't think there are any plans to make zerolib anything more than that, but Michal can correct me if I am wrong.

FrankRay78 commented 8 months ago

Implementation of zerolib is here: https://github.com/bflattened/bflat/tree/master/src/zerolib

It's the best docs. Sorry, I don't have time to write better docs for this.

I'm certainly not asking you to do this @MichalStrehovsky, but in my own travels with bflat I might investigate extending it to link to other 'standard libraries'. I'm currently planning to use the none compile option, but link to my own ported clib (not decided which one).