Click here to Skip to main content
15,121,230 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralThought of the Day Pin
OriginalGriff26-Feb-21 5:33
mveOriginalGriff26-Feb-21 5:33 
GeneralRe: Thought of the Day Pin
PIEBALDconsult26-Feb-21 5:41
professionalPIEBALDconsult26-Feb-21 5:41 
GeneralRe: Thought of the Day Pin
obermd26-Feb-21 7:21
Memberobermd26-Feb-21 7:21 
GeneralRe: Thought of the Day Pin
W Balboos, GHB26-Feb-21 6:02
mveW Balboos, GHB26-Feb-21 6:02 
GeneralRe: Thought of the Day Pin
jeron126-Feb-21 6:17
Memberjeron126-Feb-21 6:17 
GeneralRe: Thought of the Day Pin
DRHuff26-Feb-21 14:52
MemberDRHuff26-Feb-21 14:52 
GeneralRe: Thought of the Day Pin
Daniel Pfeffer27-Feb-21 7:04
professionalDaniel Pfeffer27-Feb-21 7:04 
PraiseStealing from C# - I'm shocked Pin
honey the codewitch26-Feb-21 3:27
mvahoney the codewitch26-Feb-21 3:27 
I've been repurposing a bunch of my old C# code for use as C++ code on microcontroller devices.

This is going far far better than I would have ever imagined.

For starters, C# under .NET is a garbage collected memory pig.

The environment this code gets ported to could not be more different. I have 320kB of usable RAM, no garbage collection, and an allergy to new and malloc.

And yet my JSON parser i built for it was originally written in C#. It will run comfortably on 4kB of RAM. The same code on .NET uses tens of megabytes or more.

And don't get me started on my latest endeavor - stealing Microsoft .NET's SynchronizationContext paradigm for use on my ESP32 IoT devices.

Porting the code was cake, in both of the above cases. It was almost too easy.

It's shocking to me because the differences in environments and development paradigms are profound, but the code is almost copy-paste-search-replaceable in terms of porting it.

C#/.NET:

C#
private struct Message
{
    public SendOrPostCallback Callback;
    public object State;
    public ManualResetEventSlim FinishedEvent;
}


C++/ESP32:

C++
struct Message
{
    std::function<void(void *)> callback;
    void *state;
    TaskHandle_t finishedNotifyHandle;
};


It's the same code!

Callback: C++ functor vs. C# singlecast delegate
State: C++ void* vs. C# object
Finished event: C++ TaskHandle_t based notification vs C# ManualResetEvent

It's incredible how similar it is for something so platform specific. And now that C++ has things like coroutines and awaitable methods it will be even easier to port .NET code to C++ going forward.

How did this happen? When did this happen? I'm thrilled!
Real programmers use butterflies

GeneralRe: Stealing from C# - I'm shocked Pin
W Balboos, GHB26-Feb-21 4:25
mveW Balboos, GHB26-Feb-21 4:25 
GeneralRe: Stealing from C# - I'm shocked Pin
honey the codewitch26-Feb-21 4:29
mvahoney the codewitch26-Feb-21 4:29 
GeneralRe: Stealing from C# - I'm shocked Pin
W Balboos, GHB26-Feb-21 4:35
mveW Balboos, GHB26-Feb-21 4:35 
GeneralRe: Stealing from C# - I'm shocked Pin
OriginalGriff26-Feb-21 5:01
mveOriginalGriff26-Feb-21 5:01 
GeneralRe: Stealing from C# - I'm shocked Pin
pkfox26-Feb-21 12:48
professionalpkfox26-Feb-21 12:48 
GeneralRe: Stealing from C# - I'm shocked Pin
Gary R. Wheeler27-Feb-21 13:47
MemberGary R. Wheeler27-Feb-21 13:47 
RantRe: Stealing from C# - I'm shocked Pin
Rick York26-Feb-21 7:08
mveRick York26-Feb-21 7:08 
GeneralRe: Stealing from C# - I'm shocked Pin
honey the codewitch26-Feb-21 7:12
mvahoney the codewitch26-Feb-21 7:12 
GeneralRe: Stealing from C# - I'm shocked Pin
Rick York26-Feb-21 8:14
mveRick York26-Feb-21 8:14 
QuestionRe: Stealing from C# - I'm shocked Pin
Eddy Vluggen26-Feb-21 13:36
professionalEddy Vluggen26-Feb-21 13:36 
AnswerRe: Stealing from C# - I'm shocked Pin
honey the codewitch26-Feb-21 13:42
mvahoney the codewitch26-Feb-21 13:42 
RantRe: Stealing from C# - I'm shocked Pin
Eddy Vluggen26-Feb-21 14:36
professionalEddy Vluggen26-Feb-21 14:36 
GeneralRe: Stealing from C# - I'm shocked Pin
honey the codewitch26-Feb-21 14:38
mvahoney the codewitch26-Feb-21 14:38 
QuestionRe: Stealing from C# - I'm shocked Pin
Eddy Vluggen26-Feb-21 15:02
professionalEddy Vluggen26-Feb-21 15:02 
GeneralCCC - Solution Pin
pkfox26-Feb-21 0:38
professionalpkfox26-Feb-21 0:38 
GeneralRe: CCC Pin
OriginalGriff26-Feb-21 0:50
mveOriginalGriff26-Feb-21 0:50 
GeneralRe: CCC Pin
pkfox26-Feb-21 1:41
professionalpkfox26-Feb-21 1:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.