|
Richard MacCutchan wrote: to buy London Bridge
Nah, I bought it last week and I am not selling it already.
|
|
|
|
|
I am still working on my streaming zip library, and after bouncing between other people's implementations and trying to adapt them I settled on one that was already implemented as a coroutine (which is what I needed)
I worked on it for two days, trying to get it to decompress in chunks. I got it to do a whole buffer at a time but I could not work out how to use this scarcely documented decompression coroutine in the popular minizw.h offering so that it would act like the coroutine it was supposed to be.
So eventually, I googled "tinfl_decompress"
Pay dirt! There's a sample of using it. In the comments I note my output buffer has to be at least 32kB - well that explains a lot. 32kB isn't ideal, but I can work with it if i have to.
In the comments it also notes that one of the necessary component structs its using is about 300kB!
300kB is about the amount of *total RAM* I have available on my system.
That's not counting the input and output buffers I need, and heaven forbid the zip contains a JPEG i need to decompress - I'll have no memory left!
So all this code I wrote around this function is bunk.
Fortunately, I found another implementation of a previous C implementation I was using, only someone had ported it to C#. Yay!
And then I realized one of the reasons that's such a boon. NO PREPROCESSOR. There were pages of macros in the original source. It was one of the reasons I didn't want to touch it.
The thing isn't implemented as a coroutine unfortunately, but the code is something that can be followed and adapted.
I've said it before - I love C#. I don't even use it regularly anymore, but it's nice to have around.
Less is more.
Real programmers use butterflies
|
|
|
|
|
I was expecting a waaay shorter post with that headline... But all good and interesting though 
|
|
|
|
|
I'm about halfway through converting it (in C#) to use a coroutine. God bless C#
I just need to do the state machine for the uncompressed blocks and then I'm golden.
After that, I port it back to C++ =)
Man, I love C#. If you just code such that you don't really rely on the GC the way your code is orchestrated it's cake to port to and from it.
Real programmers use butterflies
|
|
|
|
|
Quote: Man, I love C#. If you just code such that you don't really rely on the GC the way your code is orchestrated it's cake to port to and from it. This came as a surprise, because I thought C# had more language features (keywords and operators) than C++, and also a richer library. I would have also thought that GC would cause porting problems, but maybe you can just use smart pointers or change reference nullifications (I assume) to delete .
|
|
|
|
|
You'd think so, but if you use arrays for the most part (unless you're using The STL in which case you can use things like std::vector<> instead of List<> and std::map<> instead of Dictionary<>) you don't really need to worry about the GC that much. Just where you use new to make new arrays. You either change those to be fixed size (my first choice) or change them to use malloc/calloc, etc.
Most of the "core" C# stuff (streams and containers) have counterparts in C++.
I don't use "unsafe" mode in C# for this. No pointers, though maybe that would make some things easier to port.
Keep in mind I'm talking about porting algorithmic things, like a huffman inflators, or JSON parser, not apps that rely on a ton of libraries or specialized environments, like some ASP.NET application.
Real programmers use butterflies
modified 18-Jul-21 11:32am.
|
|
|
|
|
If only I could import all of the fancy-free Python SciPy library and etc into C# without too much hassle. That would make my life much easier. I know there is a way but...
|
|
|
|
|
I taught myself enough python recently to snatch some code for loading old windows 3.1 FON files, and in that case I went from python directly to C++. The main issue with Python is all the libraries.
Real programmers use butterflies
|
|
|
|
|
Agreed, it's always something extra libraries for sure. Seems to be a dll hell ting, but I would definitely like to have something like SciPy for C#... But its a lot of work to implement this...
|
|
|
|
|
Write an IronPython wrapper?
Did you ever see history portrayed as an old man with a wise brow and pulseless heart, weighing all things in the balance of reason?
Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful?
--Zachris Topelius
|
|
|
|
|
C# is a very good language, I don't think I've done any serious code in C or C++ since I learned it.
It's getting somewhat "committeefied" though ... some folk just can't leave a good thing alone.
"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!
|
|
|
|
|
Quote: some folk just can't leave a good thing alone At least some of what they add seems useful, which has generally ceased to be true for C++.
|
|
|
|
|
Except for the funky way that structs & objects are instantiated differently , it's a pretty good platform. I never did get the hang of callbacks or whatever they are termed (i.e., function pointers in C++).
|
|
|
|
|
Edit: I may have misinterpreted you. If you meant you don't get how they work in C# then disregard this comment!
It's a little easier these days with lambdas in C++. If you don't capture anything it decays to a standard function pointer meaning you can declare callbacks inline
the weird thing about function pointers in c/c++ is declaring them
the_return_type(*the_callback_variable_name)(parameter_type1,parameter_type2,...);
so like
void*(allocator)(size_t)=malloc;
That would declare a function pointer called allocator and make it point to malloc.
But once you've declared it using it is basically like using any other function:
void* buf = allocator(10);
There's your "callback"
Now as far as a function that takes one of those monsters as a parameter type - in other words, a function that takes a callback, you can declare that parameter inline in a function like you can in C#, except that you can't capture with it (unless you use std::function which is different):
static void do_my_func_with_callback(const char* sz,bool(*callback)(const char*)) {
callback(sz);
}
and then
do_my_func_with_callback("something",[](const char* sz){ printf("called with %s\e\n"); });
Real programmers use butterflies
modified 18-Jul-21 19:26pm.
|
|
|
|
|
I know how to do function pointers in C++, although I can never remember the exact syntax.
Now that I think about it, I think I can do a single delegate in C#, but there seems to be a way to put such delegate callbacks in a list, and that is where I get confused. I've been retired for a while, so I've not been doing much with it. 
|
|
|
|
|
swampwiz wrote: I never did get the hang of callbacks or whatever they are termed (i.e., function pointers in C++) I think you're referring to C# delegates[^].
Software Zen: delete this;
|
|
|
|
|
Gary R. Wheeler wrote: I think you're referring to C# delegates[^].
Yes, that's the term.
|
|
|
|
|
Got a most excellent fortune cookie (admittedly, most are more instructive than informative)>
"The memory of bad quality lasts longer than the shock of high prices".
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 |
|
|
|
|
|
Sounds true, and, ... somehow I got a thought that "quality sells itself" ...
|
|
|
|
|
These days this might be appropriate; Quality, Cost, Availability, pick 2.
The less you need, the more you have.
Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?
JaxCoder.com
|
|
|
|
|
Mike Hankey wrote: These days this might be appropriate; Quality, Cost, Availability, pick 2. These days? I am saying that for at least the last 10 years.
Ok. To be honest, I actually say: Quality, Price, Speed (deadline reduction)
Is my "Speed" the same as your "Availability"?
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
True, but more so since lockdown as everything has become harder to get.the
The less you need, the more you have.
Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?
JaxCoder.com
|
|
|
|
|
Forget the cookie. Read the remaining tealeaves in your drained cup! They are more reliable!
Get me coffee and no one gets hurt!
|
|
|
|
|
Subtitle: "My experience with Open Source".
GCS d--(d-) s-/++ a C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++* Weapons extension: ma- k++ F+2 X
|
|
|
|
|
TOTALLY NOT !
GIMP 2, Audacity, Libre, FireFox, . . .
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 |
|
|
|
|