Click here to Skip to main content
15,868,141 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 4:33
mveOriginalGriff26-Feb-21 4:33 
GeneralRe: Thought of the Day Pin
PIEBALDconsult26-Feb-21 4:41
mvePIEBALDconsult26-Feb-21 4:41 
GeneralRe: Thought of the Day Pin
obermd26-Feb-21 6:21
obermd26-Feb-21 6:21 
GeneralRe: Thought of the Day Pin
W Balboos, GHB26-Feb-21 5:02
W Balboos, GHB26-Feb-21 5:02 
GeneralRe: Thought of the Day Pin
jeron126-Feb-21 5:17
jeron126-Feb-21 5:17 
GeneralRe: Thought of the Day Pin
DRHuff26-Feb-21 13:52
DRHuff26-Feb-21 13:52 
GeneralRe: Thought of the Day Pin
Daniel Pfeffer27-Feb-21 6:04
professionalDaniel Pfeffer27-Feb-21 6:04 
PraiseStealing from C# - I'm shocked Pin
honey the codewitch26-Feb-21 2:27
mvahoney the codewitch26-Feb-21 2: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 3:25
W Balboos, GHB26-Feb-21 3:25 
GeneralRe: Stealing from C# - I'm shocked Pin
honey the codewitch26-Feb-21 3:29
mvahoney the codewitch26-Feb-21 3:29 
GeneralRe: Stealing from C# - I'm shocked Pin
W Balboos, GHB26-Feb-21 3:35
W Balboos, GHB26-Feb-21 3:35 
GeneralRe: Stealing from C# - I'm shocked Pin
OriginalGriff26-Feb-21 4:01
mveOriginalGriff26-Feb-21 4:01 
GeneralRe: Stealing from C# - I'm shocked Pin
pkfox26-Feb-21 11:48
professionalpkfox26-Feb-21 11:48 
GeneralRe: Stealing from C# - I'm shocked Pin
Gary R. Wheeler27-Feb-21 12:47
Gary R. Wheeler27-Feb-21 12:47 
RantRe: Stealing from C# - I'm shocked Pin
Rick York26-Feb-21 6:08
mveRick York26-Feb-21 6:08 
GeneralRe: Stealing from C# - I'm shocked Pin
honey the codewitch26-Feb-21 6:12
mvahoney the codewitch26-Feb-21 6:12 
GeneralRe: Stealing from C# - I'm shocked Pin
Rick York26-Feb-21 7:14
mveRick York26-Feb-21 7:14 
QuestionRe: Stealing from C# - I'm shocked Pin
Eddy Vluggen26-Feb-21 12:36
professionalEddy Vluggen26-Feb-21 12:36 
AnswerRe: Stealing from C# - I'm shocked Pin
honey the codewitch26-Feb-21 12:42
mvahoney the codewitch26-Feb-21 12:42 
RantRe: Stealing from C# - I'm shocked Pin
Eddy Vluggen26-Feb-21 13:36
professionalEddy Vluggen26-Feb-21 13:36 
GeneralRe: Stealing from C# - I'm shocked Pin
honey the codewitch26-Feb-21 13:38
mvahoney the codewitch26-Feb-21 13:38 
QuestionRe: Stealing from C# - I'm shocked Pin
Eddy Vluggen26-Feb-21 14:02
professionalEddy Vluggen26-Feb-21 14:02 
GeneralCCC - Solution Pin
pkfox25-Feb-21 23:38
professionalpkfox25-Feb-21 23:38 
GeneralRe: CCC Pin
OriginalGriff25-Feb-21 23:50
mveOriginalGriff25-Feb-21 23:50 
GeneralRe: CCC Pin
pkfox26-Feb-21 0:41
professionalpkfox26-Feb-21 0: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.