« first day (1892 days earlier)      last day (967 days later) » 
00:00 - 16:0016:00 - 00:00

4:01 PM
so does that mean the the foo it points to is also automatically deallocated?
and is that done once that reference count hits 0?
 
4:19 PM
@PeterT There is a limit on the number of un-ACKed packets you can have outstanding, so if you've used that up, you may be waiting on an ACK before you send more data. But I don't recall any reaction you're supposed to take specifically when you've received ACKs for all outstanding packets (though my memory's far from perfect).
 
@JerryCoffin what in your estimation is the timeout/mechanism that is used before sending that 1 byte packet?
 
@PeterT I don't recall--I'll have to reread the RFC (and as likely as not, find that this is entirely a matter of my memory having failed me).
 
some serverfault answer says

> Nagle's Algorithm prevents small, non-fullsize packets from being sent if there is data in transit which has not yet been acknowledged. Once an acknowledgement of all outstanding data has been received or there is enough new data in the buffer to make a full-sized packet, the new packet will be sent. There is no timeout involved with Nagle's Algorithm.
 
Okay, now I feel really old. Nagle's algorithm is as described--send tiny packet when all previous packets have been ACKed. RFC 896 points out that the algorithm I was thinking of, where it's based on a timer, is its predecessor that goes all the way back to NCP. I think I'm going to go take some arthritis medicine and quit typing for a while now...
 
4:51 PM
@JoshMenzel yes
 
5:47 PM
Hi, I am trying to compile some code with g++ on windows

#include <windows.h>

int main()
{
HDC hDC = GetDC(NULL);
GetCurrentObject(hDC, OBJ_BITMAP);
}

and getting the error

:(.text+0x2e): undefined reference to `__imp_GetCurrentObject'
collect2.exe: error: ld returned 1 exit status

Can you help me out understanding the error. The code is just to reproduce the issue ofc
 
@RonniSkansing are you linking with -lGdi32 ?
 
No, I am def just g++ ./x.cpp like a noob
and that def worked
Thanks, atleast now I understand that I was missing linking something
How did you know it was that lib needed to link?
I looked at https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-getcurrentobject and https://docs.microsoft.com/en-us/windows/win32/api/wingdi/ without seeing it.
 
it was GDI? it's one of the default libs on windows
along with kernel32
 
6:05 PM
yup, okay, it was gdi, on https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-getcurrentobject I can also follow the breadcrumb to the top and see wingdi belongs to windows gdi (https://docs.microsoft.com/en-us/windows/win32/api/_gdi/)
But how do I know that I should link exactly gdi32?
 
because that's the base GDI lib name?
the DLL is literally GDI32.dll
 
So @sehe it's more about the client being able to receive and process messages quickly and efficiently
Is what I'm seeing from the work you've shown me
There's definitely optimizations to be made in the server workflow as you're showing
 
okay, so is that because there is a naming convention between the lib name and the dll name?
Like I can also see gdi32full.dll for example.
What I am wondering about is if took another w32 api like.. direct3d.. which lib should I link with then? (asking because I cant see a direct3d32.dll, there some d3d*.dll but how do I know which file to link)
 
But it also boils down to the client being able to read and decode just as fast as the server can push
Am I understanding that right?
 
@RonniSkansing D3d is a special case, and in that case it would be dxgi
not sure if that's a *32 DLL, I don't think it is
 
6:14 PM
ah okay. Thanks, its appreciated
 
and if you needed d3d12 it's literally D3d12.lib
 
 
1 hour later…
7:32 PM
@JoshMenzel Better start cracking. If I tell you that I modified the reporting filter to read:
            if (time != previous_time && time > 2us) {
                // timer += time - 6;
                std::cout << "Broadcast took " << time / 1.0us << "μs | "
                          << time2 / 1us << "μs" << std::endl;
                previous_time = time;
            }
What numbers do you expect to see?
 
5-6
maybe up to 50
 
And that was only 40 minutes since dinner. It's actually exactly the idea here chat.stackoverflow.com/transcript/message/53032695#53032695
@JoshMenzel femtoseconds?
Doing a screengrab as we speak
 
@sehe I've been at work all day and won't be done for another few hours
so unfortunately I won't get to actually look until later
 
That's why I'll demo
 
rather, I'll be able to look
but not actually change anything until later
so is it a case of I just don't know c++?
and how to use c++ efficiently?
 
7:35 PM
Well you're getting a crash course 😉
 
Nah. I've seen many experienced C++ programmers not get subtle design choices like these right.
It's more of an elite sport.
 
@Mgetz I really want to get this up and running
 
Mind you, the change I made was conceptually simple, but very fraught with subtle traps.
 
if you don't hate the code you're writing now in 6 months you're not growing as a developer
 
well of course I hate what I started with
that's why I'm here xD
 
7:36 PM
@JoshMenzel it took me three weeks I think the first time I wrote Boost.asio code?
I'd have to check the git timestamps
 
I mean I look at c# stuff I wrote 3 months ago and go that's trash
 
and that code was and is fuuuugly
 
I just have a hard time with c++ conceptually because it's so mysterious
and there's not a lot of actual decent guides out there
 
I wouldn't say it's mysterious
 
that explain these kinds of design / runtime decisions
 
7:38 PM
but there are a lot of crappy guides
 
so I've noticed
like not 1 guide I've seen has done what @sehe has shown me
 
if you're going to understand one thing about C++ it should be RAII
because that's literally the foundation of the language
 
I saw that term thrown around all over the place
 
see the link in my post
 
but hardly anyone explains it at a good level
and how it applies to whatever scenario is being worked on
 
7:40 PM
Scope based resource management
e.g. when something leaves scope its destructor is run
 
 
so from that perspective pretty much everything else in C++ is literally about controlling the lifetime of objects somehow
 
It's a bit surprising that when there are no clients, the reported latency is higher
@Mgetz +100
 
holy *******
yeah I'd like to understand that
and where I went wrong
because from what I've seen so far, my actual concept of using async, multi-threading, and callbacks wasn't the fault
 
> It's a bit surprising that when there are no clients, the reported latency is higher
 
7:42 PM
nope
 
I bet that's also a case of RAII: When there are no connections, the shared message (MsgPtr) may be freed within the scope that's being measured. (De)allocation is expensive
 
honestly those are all optimizations
 
Indeed
 
There is a school of thought (which I agree with), which is "Write sync, optimize later"
 
@sehe assuming that'll be checked in at some point for me to look at?
 
7:43 PM
e.g. don't overcomplicate it until you need to
 
it's not even that it's complicated
it's like building an algorithm
 
this is also referred to as the "you don't need redis" approach
 
@JoshMenzel Just pushed:
> committer sehe <sgheeren@gmail.com> Wed Sep 15 21:43:02 2021 +0200

A stab in the dark: no more locks in acceptor

Instead acceptor has its own strand. And all access to connections is
from the strand.

Note that we even morphed to WeakConnPtr (weak_ptr) and use that to
dynamically "garbage collect" (on each addConnection).
 
the more I look at c++
the more I want to get it under my belt
 
I like you.
 
7:45 PM
since it is teaching me way more about management and code optimization than c# is
@sehe lol thanks?
 
If all is well, it teaches you about risk management, life priorities, hardware, bug sources etc :)
 
First thing C++ teaches you:
1. don't help the compiler, it knows what it's doing
2. The compiler is stupid can can't optimize your dumb away
;p
 
@JoshMenzel I guess most C+ programmers have this relationship with the language: this inevitable need to tame the tiger
@Mgetz Boom. Short and true.
 
3. The compiler will optimize your dumb away if your dumb is undefined behavior
 
Yeah I'm learning the compiler just hates me because it's not as forgiving as the c# one
 
7:47 PM
C# is constrained by what it is
C++ has AS-IF, the compiler is allowed to do any optimization as long AS-IF is maintained
 
Note: trivia, though latency is down, throughput is exactly the same (for 5000 concurrent clients):
 
and I'm starting to realize that
 
 
C++ also has undefined behavior, AKA nasal demons
 
yeah and I haven't quite figured out what constitutes as undefined behavior yet
because C# doesn't really have that
 
7:49 PM
@JoshMenzel I think I still see room to gut the many strands (the strand per connection maybe overkill). But seeing how things are right now, it might be a better prio to look at the client code. Could you send me your latest? (Server is fine for now)
@JoshMenzel Well, it probably does, but if you encounter that, it's branded a bug of the runtime by design.
Which is awesome, by the way. I really dig C#
 
@JoshMenzel anything for which the standard does not define a behavior, explicitly declares undefined, or is not implementation defined (implementations are allowed to define undefined behavior)
 
@Mgetz right but what does that mean in terms of code
 
@sehe it does but it's very very hard to get to without using IL directly. Or C# unsafe
 
int i = 5;
i = Add(i,5);
 
@JoshMenzel nice octal literal, more like int*foo =nullptr; *foo;
 
7:51 PM
like is that undefined?
 
what you did? no
what I did... very much yes
 
@Mgetz unsafe is the bees knees. Unpopular opinion: this is why C++/CLI is VeryNice(TM): it's basically C# with templates and unsafe by default
 
@sehe #pragma unmanaged
I used that so much when working with C++/CLI code
 
@sehe I'll have to get you the client after work
 
basically kick it back to regular old C++ unless I needed to interact with the runtime
 
7:53 PM
there's a copy somewhere but it's out of date
 
@JoshMenzel Okay! I'm going to chase my kids to bed for a bit.
@JoshMenzel I had UB in commit b545b55. See if you can spot it. It was the same order-of-evaluation bit but with a twist (lambda move captures). So the fix would be in 0818818 if I'm not mistaken.
 
@sehe huh?
lol
 
Oh, after burner: One thing I hate is that I seem to have underestimated the impact of that last refactoring. I was right that in terms of throughput it was nothing, but in terms of latency it surprsied me.
I think the async posts should add more latency which is simply not being measured now. I should move the probes for latency and maybe make them actually measure OTW roundtrips (easy, since it's local anyways). Then add proper statistical analysis. I
@JoshMenzel basically `foo(++i, i*=5) style, but with a lambda move capture involved :) It lead to very loud EFAULT syscall errors
 
hi guys
does lock in mutex or wait in condition variables put the thread to sleep and yield to another thread ?
 
8:06 PM
which ones?
the stdlib?
 
yes the standard library
 
condition var maybe? mutex maybe?
it depends
 
Yup. Up to the OS scheduler. It can be smart, it can be dumb. It's all implementation details.
 
 
2 hours later…
10:01 PM
Alright @sehe I have to go eat supper then I can resume our stuff
 
No worries
 
Thanks for helping me figure this one out
 
10:27 PM
I was doing this in the mean time
0
A: How to visualize the boost graph and perform dijkstra's shortest path?

seheAs a first step I reviewed your graph creation code. It seems hopelessly complicated. Getting On The Grid Let's simplify, based on the observation that vecS vertex container selector implies contiguous integral vertex descriptors, starting at 0: Graph make_grid(size_t size_x, int size_y) { Gr...

s/hopelessly/unnecessarily/g by now
 
10:41 PM
alright
I am back and eating food
I can actually look over the changes
what does declaring const& as a function parameter do vs not?
like for the callback handlers
 
@JoshMenzel What is "vs not"? MsgPtr& vs MsgPtr const& or MsgPtr vs MsgPtr const&?
 
both of those I guess
 
(Also, notice how subtly I made MsgPtr = shared_ptr<Message const >
 
I don't understand the combinations
yeah I was going to ask about that too
 
Okay, `T const` modifies the object to be immutable; `T&` makes a reference to a mutable object;
Now `T const&` makes a constant reference; regardless of whether the object is mutable, it cannot be modified through the const-reference.
@JoshMenzel When you share stuff in multi-threaded environments you want guarantees that no-one is doing nefarious stuff concurrently. So, I made it const. Which also means that some things won't work (like Message<>::operator>>) unless you explicitly copy the message first. This concept is known as copy-on-write and is a powerful principle
(I should probably have added that when passing arguments T passes by value, T& by reference; it doesn't matter whether T is const in that respect).
 
10:56 PM
so how do I know when to use what?
like how do I know to use Add(shared_ptr<calculator> calc, int i) vs Add(shared_ptr<calculator> const& calc, int i)
 
@JoshMenzel Pass by value if you can. Pass by reference only if you must and you understand the lifetimes of the object and the reference to it. Also, think about aliasing and sharing happening through references. In short, references + pointers invite complexity. Use them sparingly.
 
so why is shared_ptr<Message const> const& acceptable for this use case?
 
@JoshMenzel Make it a const reference if you want to avoid a copy (implying addref/releaseref) just for the pass-by-value.
@JoshMenzel Because otherwise passing a shared pointer is unnecessarily costly (due to refcounting). It's small peas, but this is C++
 
and c# is pass by reference by default
(I think)
 
I wanted to keep it a shared pointer, so that the handler can pass it to Send() for echo without ever needing to copy a message.
 
11:04 PM
right
that's what I wanted
pass without copying
 
@JoshMenzel Indeed. Except for value types (e.g. primitives and structs). However there are some funky boxing rules involved e.g. when capturing locals which makes it a little more diffuse.
@JoshMenzel If I didn't want/need to share the object further (like in the Send() from the handler example), I'd have just passed Message const& without any smarts (just pass *p instead of o)
I'm going to mind my bedtime today. But I'll keep an eye out for the client code update.
 
@sehe sure
I can do 2 things
I can give the client as-is now
or I can take a crack at optimizing it myself
and see how far I get
 
Your choice. I'll be afk for ~10h, so go for it!
 
I'll give it a shot but given my weak understanding I'm not going to expect much
I think I'd like to try anyway
see what happens
 
I'm already impressed with the code. You underestimate how much trouble I've had figuring stuff out like the scatter/gather (buffer sequences), strands, thread safe queues, etc. etc. So, not bad at all.
 
11:15 PM
@sehe you mean what I started with?
 
Yeah. It is a lot of complicating factors. Nothing to huff at. I've seen C++ programmers have trouble with these. So, you're showing lots of potential. And the right mindset to acquire it, I think.
(Oh, and I love to see learners not getting stuck in archaic cargo cult code; e.g. you use structured bindings, which is refreshing compared to all the questions on the main site)
 
I guess I didn't even know that was a thing haha
 
Actually, you can see me do the oldfashioned pair access (for (auto& kvp : m) so you have to use kvp.first or kvp.second; that was for shame, but apparently we can't capture parts of structured bindings in lambda captures).
 
yeah
I guess that's the biggest struggle is that there's so much stuff that's outdated
 
If you wanna lol, this is c++03 style:
    for (std::map<int, WeakConnPtr>::const_iterator it = map.begin();
           it != map.end();)
    {
        if (it->second.expired())
            it = map.erase(it);
        else
            ++it;
    }
 
11:22 PM
O_O
 
That's an approximation of this line:
    // c++20, otherwise clumsy iterator loop
    std::erase_if(connections,
                  [](auto& kvp) { return kvp.second.expired(); });
 
also yeah the in messages queue I got rid of
I wasn't using it
once I got the callbacks
ThreadSafeQueue<OwnedMessage> qMessagesIn; // why is this here?
That can go away
OwnedMessage can go away
what's the [[nodiscard]] and [[maybe_unused]] for?
also I wanted to ask about the Message
in the Append method
the one that has a signature of std::string& data
when I do const char* data_cStr = data.c_str() and call Append(data_cStr);
why don't I have to call delete or free data_cStr?
there's also a bug in the GetString method, needs to have return after the dst.assign in the if block
dst.assign(length, body[sizeof(size_t) + offset]);
return;
 
00:00 - 16:0016:00 - 00:00

« first day (1892 days earlier)      last day (967 days later) »