« first day (1536 days earlier)      last day (1308 days later) » 

8:34 AM
I have two integers represented by type mpz_class, x and y. I want to take the floor of their division. But it seems GMP's floor function only takes argument mpf_class and returns mpf_class.
Is it really the best way mpz_class z = mpz_class(floor(mpf_class(x)/mpx_class(y)))
That seems like a lot of unnecessary temporary objects
 
 
2 hours later…
10:15 AM
@northerner isn't mpz_class using integer arithmetic when dividing anyway?
 
10:43 AM
Question about virtual inheritance. Suppose we have something like this:
```
class Top { public: int t; };
class Left : public virtual Top { public: int l; };
class Right : public virtual Top { public: int r; };
class Bottom : public Left, public Right { public: int b; };
Bottom b;
```
How is it possible that virtual base constructor is called first here but the shared region ( the region coming from virtual base ) is placed at the end of the object in memory ?
 
@domocar1 I don't think I understand the question, with any kind of multiple inheritance you adjust the value of "this" when calling base class members
or are you talking about the vtable? I don't think I've seen the vtable pointer being placed at the end, which compiler does that?
 
So I found online that this should be the memory layout of the object b in memory:
| |
|------------------------| <------ Bottom bot; // Bottom object
| Left::l |
|------------------------| |------------------|
| Left::_vptr_Left |-------| | offset of Top | // offset starts
|------------------------| |-------|------------------| // from left subobject = 20
| Right::r | | ... |
The thing I don't understand is why is the Top::t placed at the end of the object while , as far as I'm concered, virtual base constructors are called first .
 
what does the order in memory have to do with the order the constructors are called in?
 
Hello, I have a question that is tangentially related to C++
Suppose I had some kind of class that represents an object like a coordinate board, and I want to have operations (member functions) for that object, but these operations need to be done as quickly as possible (because I need to perform millions or billions of operations). Is there a way to create a class-like object that has the encapsulation of a C++ class but chops off a lot of the overhead and has an "internal structure" which is more akin to something like assembly?
 
@PeterT I guess there isn't haha but I don't seem to grasp that point. Intuitively, at least for me, the order should be synchronized.
 
10:56 AM
@Rithaniel what specifically are you talking about beyond inlining all kinds of stuff and link time optimization?
 
So, this isn't a specific thing, but more so me trying to expand my knowledge base. Though, expanding on the idea of a coordinate board, suppose you were using a class to represent a chess game and you wanted to have an AI playing the game. It is searching through a tree of games with tens of millions of nodes. It needs to evaluate each node very quickly to be useful as an AI
Like, my naïve version of a board evaluation function would have to have several for loops, evaluating possible moves for every piece. That seems like it would be very time-consuming
 
ok, but now you're talking about the algorithm you choose, whereas previously you were talking about implementation details
I mean you can do various optimizations, like aligning the necessary data to chache-lines and if the compiler doesn't do a great job, you can employ SIMD intrinsics for the core computation part
 
Well, the algorithm idea was more so constructing an example of why you might need to have member functions that operate more efficiently than they would at standard. But I will now be looking aligning chache-lines and SIMD intrinsics
I'm a novice about this stuff, so is there maybe some required reading before I do that?
 
I don't even know what we are talking about in general? Like micro optimization techniques?
If so I'd say reading up on the memory model of the platform you're targeting is a good starting point
 
11:17 AM
I suppose I could try and explain it a little bit better, but, again, I'm a novice so I might not explain it with the correct terminology.

It's my understanding that a lot of runtime in a program can be lost to function calls and the machinery of various loops. Particularly, these tiny time losses become compounded when you make many function calls or have many nested loops. I'm wondering, if you're in a situation where that time loss is appreciable, are there any easy ways to try and remove this overhead.
 
function call overhead is mitigated by inlining functions and I'm not sure which loop overhead you're referring to
 
Like, for loops. You have to initialize the index and then check and increment it each time. By itself, it's tiny, but if you only do three operations in the loop, and then go through the loop thousands of times, it can become appreciable
 
if you want to unroll loops you can do that
 
 
2 hours later…
1:24 PM
Hello! I'm in the slow process of refactoring our simulation app to eventually try and make it multithreaded. The situation is a bit complicated but basically, we use MFC for our app (CWinApp), main window (CFrameWnd) and main view (CView), and we pass the CView HWND to the third party 3d renderer that we use (OpenSceneGraph -- OSG).
OSG handles the events of the message queue of the CView. We have events that "come from the simulation" and should be acted upon by the MFC UI (e.g. pop a dialog when the simulation is completed), and we have MFC UI dialogs that should be acted upon by the simulation (e.g. the user wants to pause the simulation).
My question is: in this context what is the general suggested approach in passing the events between the MFC UI and the simulation?
 
1:36 PM
@Vaillancourt PostMessage
 
@Mgetz Ok, this is one of the the three ways we do things at the moment. I'm not so familiar with MFC, so the way we should do it is via "delayed, queued" messages?
 
@Vaillancourt just post it... let windows sort it out
 
(We also have some code that SendMessage, and some code that "set a flag, tackle it on your next OnIdle.)
 
it's responsible for handling the threading
right SendMessage works too
 
But is it typical to use both, or do people usually stick to one (either Send or Post)?
 
1:41 PM
Well if you want async sometimes and synchronous other times you'd use both
 
Yeah, ok, so it depends on the needs.
I guess if we're to add more threads to this, I should start thinking about going async as much as possible?
 
1:55 PM
@Vaillancourt depends on how you want to add threads? Personally I did it with coroutines and the winrt helpers
but that has other things I have to deal with that complicate things
 
@Mgetz Heh looks like I don't have a clue about what this is.
 
Thanks, I'll bookmark this! It appears it needs c++20 for coroutines, which needs vs2019 and we're still on vs2017.
 
2:11 PM
@Vaillancourt true... and I'd probably wait for VS16.8 anyway at this point
 
I haven't looked into how I would add threads exactly; the gist of it is to have the rendering on one thread and the "simulation" on another, and sync on the "position of the objects in the world have been updated" .
 
@Vaillancourt That's why I moved to that solution. But if the simulation is long running an explict std::thread might be the right choice.
in my case I have lots of very quick things running all the time
 
yes, so a threadpool would do a better job there
 
correct, whereas it does horrible for long running stuff
tbf I also had to deal with stupid apartment threading issues that made things not fun
in fact I had to create a thread that lasts as long as I'm doing stuff in the thread pool... to ensure the threadpool has a MTA
 
What's a MTA?
 
@Mgetz Thanks I'll take a look at it.
 
Basically it's COM's way of allowing people to code for either a UI paradigm (implicit synch) or explict (multithreaded, locks everywhere)
 
don't, everytime you see "COM" just turn around 360° and moon-walk away, hehe
 
@PeterT if you're coding on windows? It's de-facto unavoidable at some point
honestly it's not as bad as people make it out to be
 
true, you can't really avoid using it sometimes, but I think most people can avoid writing their own COM objects
 
2:27 PM
Yeah, unless you're writing a library that needs that power... it's really not useful to write your own. Although MS has made it a lot easier with the WRL and winrt templates for it
no more manually implementing IUnknown anymore
 
yeah, I don't think we need that here, though
Maybe someday? What if we changed the "UI" from MFC to a c# window and asked the render to render in there...
 
honestly? I only ran into it because I wanted cancellation. If I'd been patient and waited for C++20 cancellation that wouldn't have been an issue.
@Vaillancourt the app I was referring to was also MFC
 
@Mgetz Oh, okay!
 
3:04 PM
This looks like a nice challenge to have a 1:1 behviour between the UI and the simulation, while keeping the rendering when dialogs are there, blocking.
Thanks all for the tips :)
 
 
1 hour later…
4:11 PM
::pow(2, n)) what does this mean??
if (visited.size() == static_cast<unsigned int>(::pow(2, n)))
 
it's just "2 to the power of n"
the ::pow is just saying "use the pow name in the global namespace"
which is the cmath pow function
 
oh cool thanks
i cant see the point of casting there either
 
pow is a floating point only function, so it returns a float, if you increase the warning level enough you might get a warning for comparing a float to a size_t
btw. that code seems really sub-optimal
 
ah yeah, good detail
 
"1<<n" is a lot faster and doesn't do weird float conversions
and this case does not look like you have negative values for "n"
 
4:18 PM
not my code
reading others
thanks for comments though, super useful
ive decided thats horrible code
 
it's "competitive programming", from what I've seen people doing that make it a matter of pride to write bad code
 
thats just using small variables or as little lines of code as possible
 
4:37 PM
@Permian why... would someone ever write this for a static base
for powers of two on any compliant system you'd just to a left shift
 
yeah i agree its strange now @Mgetz
i guess they like using the features
haha
 
/shrug
 

« first day (1536 days earlier)      last day (1308 days later) »