|
Did you hear about the dedicated chemist who got absorbed in his work?
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
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:
private struct Message
{
public SendOrPostCallback Callback;
public object State;
public ManualResetEventSlim FinishedEvent;
}
C++/ESP32:
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
|
|
|
|
|
OK - now it's time to really "put the pedal to the metal" and port this to C . Those last bits of fluff will fade away.
Ravings en masse^ |
---|
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein | "If you are searching for perfection in others, then you seek disappointment. If you seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010 |
|
|
|
|
|
In recent years I haven't found a good use case for strict C development except in one case (ESP8266 IDF) due to a broken developers framework.
Even my little 8-bit monsters, while not supporting most of the STL, will handle classes and functors and things like that just fine, with just 4-8kB of RAM.
I mean, several years ago it wasn't uncommon to find devices with less RAM than that. Now you have to go out of your way to find them.
So don't get me wrong - I'm not saying those use cases for C don't exist. But they seem rare these days, and I personally don't tend to encounter them.
Real programmers use butterflies
|
|
|
|
|
The suggestion was purely for sport programming.
Actually, it's been a very long time since I've done sport program. That was for FORTRAN callable assembly functions on a VAX/VMS system - myself and a (now deceased) friend would compete for who could make the most compact version of a function.
In your specific case, any space saved could be used to install some games. If none found are small enough, that becomes yet another challenging project!
Ravings en masse^ |
---|
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein | "If you are searching for perfection in others, then you seek disappointment. If you seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010 |
|
|
|
|
|
When I was younger, sport programming involved rewriting autoexec.bat and config.sys to play a game: getting the sound card and mouse working together, sometimes with EMM386, sometimes without - that kind of thing.
I'm pretty sure I spent more time and effort on that than playing the damn game sometimes!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
"I didn't mention the bats - he'd see them soon enough" - Hunter S Thompson - RIP
|
|
|
|
|
I remember doing that for my job. My product ran under the DOS4GW DOS Extender (just like DOOM), and I had to work really hard to have enough real-mode and protected-mode memory. I had to tweak CONFIG.SYS and AUTOEXEC.BAT settings to both allocate memory the way I needed, plus support UI languages and such.
Software Zen: delete this;
|
|
|
|
|
Quote: For starters, C# under .NET is a garbage collected memory pig.
That is one of several reasons why I have nothing what so ever to do with it.
"They have a consciousness, they have a life, they have a soul! Damn you! Let the rabbits wear glasses! Save our brothers! Can I get an amen?"
|
|
|
|
|
I don't mind it because all that memory use buys me things, and I have more RAM than sense on a modern desktop anyway.
Still, it is a little off putting at first.
There are some great ideas in there though, like the way you can pass calls around to execute on other threads instead of having to do synchronization through read/write barriers.
Real programmers use butterflies
|
|
|
|
|
I did something similar just the other day in C++. At least, it seems to fit that description. Regardless, yes, there are some interesting things in there.
"They have a consciousness, they have a life, they have a soul! Damn you! Let the rabbits wear glasses! Save our brothers! Can I get an amen?"
modified 26-Feb-21 13:24pm.
|
|
|
|
|
honey the codewitch wrote: How did this happen? When did this happen? I'm thrilled! Easy, C# based on it.
Where is malloc in this code btw?
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
I don't use malloc or new directly in any of that synchronization context code. I use xRingBuffer methods which use malloc on creation based on my digging.
why do you ask?
Real programmers use butterflies
|
|
|
|
|
honey the codewitch wrote: why do you ask? Because that's the major difference.
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Honestly, I don't know what it is you're on about.
The difference between malloc and new?
Neither of those Message structures that I listed have anything to do with memory management - malloc, new or otherwise.
As far as I can tell, you took two words in my comment (the allergy remark) and started a whole cryptic subthread about them to the point where I wish I simply had not used the terms. The whole thing is just... what?
Real programmers use butterflies
|
|
|
|
|
honey the codewitch wrote: Honestly, I don't know what it is you're on about.
The difference between malloc and new? One is under management, the other isn't.
honey the codewitch wrote: Neither of those Message structures that I listed have anything to do with memory management - malloc, new or otherwise. Sure, no unboxing there. No memory management involved in your example-code. It pure as C.
honey the codewitch wrote: As far as I can tell, you took two words in my comment (the allergy remark) Re read it, and can't find the remark.
honey the codewitch wrote: started a whole cryptic subthread about them to the point where I wish I simply had not used the terms. The whole thing is just... what? So what terms would you prefer?
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
|
SENNET?
A call on a cornet signalling the ceremonial entrance or exit of an actor in Shakespearean theatre
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Nope
"I didn't mention the bats - he'd see them soon enough" - Hunter S Thompson - RIP
|
|
|
|
|
Hmmm,
I can't seem to solve this one! I have to leave in a few minutes so I will leave some notes as they might be useful to someone else.
1.) Cornet is a synonym for a cone (specifically a 2D plane that has been folded into the shape of a funnel) which could indicate that this is the second cone shaped clue[^] this week. Or it could just be a coincidence.
2.) 'dramatically' is frequently used as an anagram indicator.
3.) Cornet is also a synonym for lieutenant.
I couldn't solve it but I probably wasted too much time chasing cones.
|
|
|
|
|
I stopped thinking about it. Cornet=horn? Cornet blown=alarum, blared, tattoo, tooted? Or is blown an anagram indicator? Is shift the definition or an indicator for moving letters from the front to the back or vice versa? Too many possible parses.
I didn't know about the lieutenant thing, which could then be ensign, but that doesn't fit either.
|
|
|
|
|
Why did you post the solution so early? It's supposed to have four hours ...
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I thought it was 1 o clock ?
"I didn't mention the bats - he'd see them soon enough" - Hunter S Thompson - RIP
|
|
|
|
|
No, it's four hours, but it's supposed to be posted at around 09:00.
I found retcon as an anagram, but I assumed it was an acronym not a "real word"
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Correct. It's an acronym and not a real word, even if those twits at Merriam-Webster promoted it to such.
|
|
|
|