« first day (1893 days earlier)      last day (966 days later) » 

12:14 AM
also I'm not sure if I can do c++20, I'm still on c++17 right now
so that std::erase_if may not be available
 
12:34 AM
@JoshMenzel data_cStr doesn't own anything, that's std::string's job which will manage the memory
@JoshMenzel You have the clutch method above
 
aha
I found the biggest issue
I wasn't using the asio::post
I didn't understand that the asio::post can literally be ANY function you want
and literally do ANYTHING you want
 
@JoshMenzel I noticed that. First I was planning on getting rid of allocations in the Message implementation (and perhaps making things more typesafe/convenient). But you know how it went already
 
yeah
it's literally that this method of doing things isn't covered
in any guides I read
or youtube videos I watched
(even the ones from 2019/2020)
 
@JoshMenzel My rationale here was that doing a thousand weak_ptr::lock() may take signifiicant time. I was a bit hesitant about the latency introduced by posting 1000 extra tasks first, but at least they get out of the way of timedBcast
 
so the handle.lock is replacing the connections mutex I was using earlier?
 
12:38 AM
@JoshMenzel post, dispatch and defer aren't new. In fact, they're the the eldest ingredients of the async executor model
 
@sehe strange that this wasn't talked about at a high level in anything I looked at
 
Partially. Actually, the lock() is what checks weak pointers, so it replaces the need to synchronize on removal of dead connections.
The other win was no longer having to synchronize manually on `connections` because all the access is from the `Server::strand_`
 
so I was actually pretty close
 
@JoshMenzel Yeah, it's not highlevel. But it's bread and butter in context of strands, I suppose, because often you need to force some work to happen on a strand
 
right and never having done this
 
12:40 AM
@JoshMenzel Yeah you did mention it before I mentioned it.
 
at least not in c++ and not to this scale
So am I just bad at researching then?
Just trying to figure out why this got missed
 
The first changes were very typical: reduce allocation, do less work.
This step is not very typical (trying to reduce lock contention and increase concurrency).
I feel I have to point out once more that I think the timing numbers are way too flattering. You actually only time the dispatch of tasks, no longer reflecting any true latency - but it will sure be there (if only in the post to another thread).
@JoshMenzel I think you're just less good at patience, but make up for it with quick mind and good research.
Keep in mind, some of these coping strategies are based on experience; they will never come with ease. Not everything can be taught in tutorials because it all comes down to the nitty gritty details, the bytes and threads.
 
Makes sense
 
Do you remember how much time I took just reading through until I could piece together a story of how the access/usage patterns would be? That took hours.
 
@sehe right but I should be able to send as much as I want and not he constrained by lock access and memory copies yes?
 
12:47 AM
Then I had to mull things, basically thinking up ideal solutions/approaches and how they could maybe fit into the picture.
 
Right and I'm surprised you did
 
@JoshMenzel You're always constrained. There is no silver bullet.
Locks haven't "gone away" either. It's just that we can entrust the library with them (they're hidden in the strand execution service implementation details).
 
So then I guess a lot of the terrible problems I've had were a result of just bad designing in the implementation of the code
Like there's a reason I didn't trust boost to run threads on its own(nor did I know how)
 
The idea is that (a) they'll have the scalability figured out (they do). (b) they can make all kinds of smart decisions, taking advantage of the fact that locks are not acquired during async tasks (blocking the pool) and they happen on edges between tasks, and the scheduler can take into account (e.g. when continuations are already on the same strand, I imagine).
 
Nor entrust it with the locks(I didn't know strands were a thing nor how they were actually supposed to be used until the scatter/gather)
 
12:51 AM
@JoshMenzel It does pretty much literally what you had, except it comes with robustness.
You should check the documentation for the default number of threads (ISTR it was 2*hardware_concurrency` when avaikable, but haven't checked). That's another thing: hardware_concurrency() isn't guaranteed to run useful info. It may legally always return 0 on a platform.
 
Yeah I have to look at that
But right now I'm seeing this optimization
And I'm wincing
Because I realize how horrid the main assembly this has to go into is
 
Are you going to run it in a mixed mode assembly, or was that just CLR speak for dll?
 
DLL
The game sdk is c++
 
capiche
 
And is available on Mac, Linux and windows
But I might just end up starting from scratch
Because of the poor RAII understanding I have
 
12:54 AM
Once upon a time I promised myself to go to bed. I'ts almost 3am again. Peace!
 
Peace dude I'll hit the client to you tomorrow thanks again
 
1:53 AM
In a thread which has not ever called and would never callasio::io_context.run(), must I invoke post() dispatch () to dispatch tasks to the thread which has called asio::io_context.run()?
 
 
3 hours later…
4:24 AM
In a thread which has not ever called and would never call asio::io_context.run(), must I invoke post() or dispatch() to dispatch tasks to the thread which has called asio::io_context.run()?

Is it safe to directly call asio::async_write() or asio::async_read() in a thread which has not ever called and would never call asio::io_context.run() to dispatch tasks to the thread which has called asio::io_context.run()?
 
 
8 hours later…
12:37 PM
@John That's basically how that works. Yes, it's also a "cheap" way to implement a task queue (see e.g. stackoverflow.com/questions/25925256/…)
To the first part: yes. (s/must/can/)

To the second part: yes (but)
The "but" is that you're responsible for thread safety/synchronization. E.g. a tcp::socket object is not thread-safe. You should only call methods on it from one logical thread (e.g. strand) or critical section (e.g. using mutual exclusions, mutex)
@John extended my answer a bit here
0
A: In a thread which never calls asio::io_conterxt.run(), must I invoke post() to dispatch tasks to the thread which has called io_context.run()?

sehe In a thread which has not ever called and would never call asio::io_context.run(), must I invoke post() or dispatch() to dispatch tasks to the thread which has called asio::io_context.run()? That's basically how that works. Yes, it's also a "cheap" way to implement a task queue (see e.g. stacko...

Next time, please consider linking to your question if you posted on the main stie
 
1:48 PM
Hii , everyone. I am a new learner in C++ & am learning about binary number system rn.
I really need your help since I am not able to understand why it is used. Mostly , online I have read that since switches have only 2 buttons , ON & OFF. We use BNS.
 
It's a lot easier to do things when things are true or false? Not unsure?
 
But I want to Q that in a computer , it is said that everything which is working inside of it like apps . They are all binary. Then , when we talk about alphabets having BNS. I read that t is represented as 01110100. So , what does this mean.
 
Also transistors are either on or off generally speaking, creating a third state results in strange behaviors in most cases
it means it's base 2
that's all
 
Like for t 01110100 = off on on on off … doesn’t make sense right.
 
everything else is just human mapping of a number to a bit of data
 
1:52 PM
@Mgetz Ok
 
that's 116 decimal?
 
@Mgetz Hii. Thanks for responding. I have added more to my Q. Hadn’t finished yet. Sorry.
 
please don't ping reply EVERY SINGLE TIME
it's extremely annoying
 
nwp
Lmao
 
and yet you did it again
...
you don't need to mention me in your reply
 
1:54 PM
Ok. I may have mistaken. You can take any letter or number. They all work the same way right. For example , 11 in decimal = 1011 in binary
 
yes
 
Great. We can discuss now then.
 
nwp
Due to how computers are built they can only represent on and off in their flipflops. Then you use those to make registers and end up with a number of bits (64 for example). And now you have to figure out how to represent a "t". All you have is a bunch of bits, so you assign some arbitrary bit sequence to represent it.
The knowledge that 01110100 is supposed to be a "t" has to come from outside. Usually in programming languages that knowledge is represented as a type.
 
computers are essentially very fast four function calculators
although technically you can implement them as one function
 
Ok. So , it is our choice to assign 0 or 1 as off or on. In reality , we can do anything with them. Like you wrote. We can assign a variable ‘t’ a value in binary. Is this right what I’m typing ?
 
1:59 PM
so I'm not going to get into the hardware quirks (logical high/low), but generally yes
 
Also , I also studied about quantum computers & ternary computer. In them , you can store value with more than 3 logical states & even more in quantum especially
 
nwp
Mostly. For example that t is that number is because of the ascii table which I believe is part of some standard, so deciding that you want some other number to represent t will be tricky, but basically yes, it's arbitrary.
 
Why is it like that then ? So , why is it that computers necessary need only binary numbers system.
 
so a ternary computer is still just a binary computer such that the logic is built around the value 3. Quantum computers aren't computers in the same sense at all. They are their own thing
 
nwp
They don't. You can make analog computers or computers with more states. It just turned out that the binary ones won over the market.
 
2:03 PM
either way there are no inherent advantages to values that are non-binary except quantum computers
 
Ok. Interesting. Thnx a lot. I really enjoy this discussion & which actually tells my gut to explore more of computer science. The problem in schools is that we do know how to code but don’t understand what is happening inside & how can this be used in future.
 
because it's mostly not useful?
unless you're dealing with hardware at a physical level in most cases you just need to know that these are things
 
nwp
That's a bit of a personal preference. Some people like to know which current goes through where when they write an instruction. Others do CreateWindow and don't care how it's done, they just want a window.
 
It may not be as you’re saying but I think that unless you don’t know what is happening inside. The subject actually doesn’t give much of a feel. For example , in my case. If there could have been a simple practical experiment to show what the textbooks mean to say or a animation so as to understand what is happening.
 
Well textbooks are often reflecting realities that haven't been valid for years
case in point... memory management
 
2:07 PM
Yeah , I understand. Thank you once again btw. I’ll text you both soon.
 
Is that a threat :)
 
 
4 hours later…
6:20 PM
@sehe so I implemented your changes and holy toledo
on the server side that's insane
the biggest issue that I saw was the memcopy
and how functions should take in parameters
in c++ I think the objective is to use as much no-copy by reference type of parameters as possible
do I have that right?
 
Hi, I have a code that's supposed to take in strings using getline from the input but the first getline command is getting skipped, any ideas?
code snippet:
if (ans == ("strings"))
{
string a{}, b{}, c{};

std::cout << "Enter the lower bound of a range:\n";
std::getline(cin, b);

std::cout << "Enter the upper bound:\n";
std::getline(cin, c);
 
@JoshMenzel depends?
 
@Electrical_engineer_student what do you mean by "is getting skipped", just "returns immendiately? If so then you already had something in stdin when you arrived at that code
 
^
 
reply to PeterT: getting skipped means it is not waiting for the user to press enter and asking for the upper bound straight away.
I used cin.clear() but that does nothing. While debugging, the "enter the lower......" line does not wait for the user to input anything and goes on straight to the upper bound line but then stops there(which it should). But why is it not stopping at lower bound part?
 
6:37 PM
@JoshMenzel Like I said yesterday, quite the opposite! By value everything, please. Less aliasing, less sharing, less locking, less head-aches. However, in this case you had an immutable message that was a going to be replicated to literally thousands of connections.. so that totally calls for §std::shared_ptr<Message const>§
 
but if I do this:
 
Ow. Ipad keyboard. Not even gonna attempt to edit.
 
else if (ans=="numbers")
{
double a{}, b{}, c{};
std::cout << "Enter the lower bound of a range:\n";
std::cin >> b;
std::cout << "Enter the upper bound:\n";
std::cin >> c;
}// this code works as expected without any skipping of getline cin
 
7:07 PM
@sehe ah okay
so it's literally down to byref or byval
and the use cases for them
I think that's where I went wrong the most
would that also explain the slowness and complexities involved in doing this for c#?
the byval byref
(I didn't get a chance to take a crack at the client side yet)
 
@JoshMenzel potentially? C# is its own monster
but probably not
you don't tend to need byref and byval until you get to massive throughput where allocations start to really kill you
and even then I'd wait until the profiler started to tell me GC was my major issue
 
7:38 PM
@sehe so normally I would just pass Message not Message const&
Correct?
I guess what does the pass by value look like
 
8:33 PM
@JoshMenzel Yeah if you wanted to share the object. However to manage the lifetime you needed more. Of course, you can try to garbage collect. But I'd use allocate_shared with a pool allocator before that.
`T` - by value, `T (const)&` by ref
`T (const)*` by raw (non-owned) pointer, nullable
`unique_ptr<T>` owning pointer (move-only, as in can't copy)
`shared_ptr<T>` owning pointer (refcounting)
`weak_ptr<T>` non-owning observing shared pointer
@JoshMenzel It's where everyone goes wrong the most because it's one of the sole reasons to use C++. Value semantics by default makes for high level of control.
 
8:49 PM
Ah okay
Is there some reason this isn't covered or talked about much?
 
(by the way, I think if you surveyed c++ programmers, less than 1% would know about allocate_shared, likely)
@JoshMenzel It's talked about all the time. It's just that most people don't "get" it when they hear it. They're usually full of assumptions coming from other languages. It takes time to even notice that there are microbes in your drinking water, let alone pay attention to herding them :)
If you take a random sampling from questions I bet that >60% is about value/ref semantics in some way shape or form.
 
 
1 hour later…
10:07 PM
@sehe ah ok
so how do I get to the point of being able to find and address those types of issues?
because they are all over the place in guides, tutorials, examples, and sample code snippets
 
 
1 hour later…
11:20 PM
@JoshMenzel I'd say, rely on yourself. You have to build and trust your own understanding. Use tools (asan,ubsan,tsan; valgrind) to spot when you're making a lifetime error, which will often go unnoticed until they crash (or launch the nuclear missiles).
This is never going to come from tutorials. It's like people who want to become great at chess by reading a book. Or multiple books. They're never going to get there.
If you keep sharpening the axe - as you quite clearly already have done for a long time - one day you'll find yourself either just seeing optimal plans or improvements, or having the trust and calm to attack problems with your tools (a profiler!).
 

« first day (1893 days earlier)      last day (966 days later) »