« first day (577 days earlier)      last day (2500 days later) » 

00:02
hmm
will look into it thanks!
Ok I have another question... I have a
map<string, json> _mValidators;
if (_mValidators.find(id) == _mValidators.end()) {
//I found it
}else{
//I dont have it
}
do you guys see error in this? because I don't get correct results :/
nwp
nwp
Looks reversed.
@Dariusz Looks backward. find will return end() when it doesn't find something. If it does find it, it'll return some other iterator (pointing to the item it found).
yes, your branches are switched
really? so if he reach the end he finds it?
wait
crap
that explains the pain I was getting... thanks!
00:33
If all you want to do is see if the key is in the map, you can use _mValidators.count(id)‌​, but if you want to do something with the found element, you'd probably want to use find @Dariusz
hmm thanks!
 
1 hour later…
01:49
Guys, from the CMake docs
]Both commands are intended to replace use of add_test() to register tests, and will create a separate CTest test for each Google Test test case. Note that this is in some cases less efficient, as common set-up and tear-down logic cannot be shared by multiple test cases executing in the same instance.
What the hell is 'instance'? :) of course this is the only occasion of it on the page :)
 
1 hour later…
02:49
ok another weird one, I have struct with bool add; and when I try to set it up I get this error
error C3490: 'add' cannot be modified because it is being accessed through a const object
const objects are const
I didnt make one
but I called it from lambda, maybe thats the problem
yep thats it, cant call it from lambda
the lambda is translated to a function object with it's operator() being const
[=](whatever) mutable { } // this one is not const
ah I see
oh o.o
interesting
03:23
which is faster, use map or vector if I want to find an item by id?
This is valid, right? static constexpr int const& num = <some int temporary>; use(num); // or maybe static_assert(num == 42) to use in a constexpr context
@Dariusz Depends on what you mean by id and what loads / operations you'd use on the container, but probably vector
id = uuid, Its either map.find() or vector for loop (if id == id)
Ahh, in this case, it depends on how many elements you have. Using vector and one of the standard find algorithms will be faster for small numbers. If you can sort the vector based on the uuid, then use a binary search (the algorithms library also has those), that would likely also be better than map for lookups.
interesting
well I expect vectors to be between 700-60k big (extreme cases more)
map isn't the best data structure because it's a "linked list data structure". Even unordered_map is kind of linked-list like (there has to be linked lists). But I'd probably just use unordered_map...
03:30
hmm interesting, thanks! I'll have to do some tests but good to know will try unordered map
If it's really performance critical, you might go look for some other hashmap libraries out there. I saw this cppcon video which shows the design behind some hashmap that google implemented. I'd probably look into that library if I wanted a better hash map
mmm interesting!
thanks! :D
04:26
@Justin 45 min in to the talk, I understand 10% :D
It's not the best talk, and it goes into some really difficult details. Sorry, I hadn't meant to ask you to watch it because it goes deep into the implementation details. I was just putting that here for reference if you do need a really good hashmap.
 
3 hours later…
07:13
... Does lifetime extension of temporaries make sense at compile-time (in constexpr)?
For context, I'm not sure I agree with the arguments presented in this answer
It wouldn't make sense to me for C++ to throw out the idea of lvalues and rvalues and temporaries just because we are working in constexpr; that's part of the type system...
Huh, this doesn't compile, although - strangely - if I make the variable static, it works
That whole Q is basically about whether static constexpr std::initializer_list<int> foo{ 1, 2, 3 }; static_assert(some_constexpr_fn(foo)); is allowed.
It makes sense to me, and I feel like it should be allowed. But apparently the reason why clang and msvc are rejecting it is that the temporary array created to get the values for the std::initializer_list makes it so that we have a reference to a temporary
But initializer_list is supposed to have lifetime extension similar to const&.... But that answer says that lifetime extension doesn't make sense in constexpr.
C++ is weird
 
1 hour later…
nwp
nwp
08:50
@Justin It does make sense. And once we have constexpr new and constexpr delete people will eventually stop with the "memory allocation makes no sense in constexpr land".
 
1 hour later…
09:54
@Justin It doesn't. Constepxr is explicitly about state without runtime instances. At all. So there's nothing to have an address, let alone anything that could be bound to a reference, let alone to a reference whose lifetime is different from others.
nwp
nwp
10:44
@sehe That doesn't make any sense. std::array a = {1, 2, 3}; for (auto it = a.data(); it < a.data() + a.size(); it++) sum += *it; should be totally valid at compile time, even though you take the address of stuff.
Same goes for const auto &i = 42;. It should be valid in a constexpr function because reference lifetime extensions allow it.
mmm
nwp
nwp
I don't see any contradiction or problem in "The address of a constexpr object is constexpr".
Well. The address would not be an address, but the pointer would be a constant, then. Agreed
11:13
Hi, I have a beginner's question here:

I have a header file that contains something like:

class MyClass {
public:
using customType = SomeClass::templateMethod<int 'n'>;
static customType typeInstance;
static void method;
...
}

And in my .cpp file, I have:

using customType = SomeClass::templateMethod<int 'n'>;
customType MyClass::typeInstance

void MyClass::method() {
SomeClass::utility<MyClass::customType>;
SomeClass::utilityMethod(typeInstance);
}

It compiles, so that's not the issue, but having to duplicate 'customType' and 'typeInstance' seems weird to me... Should I be doing someth
nwp
nwp
Did you intend customType to be a pointer to member function? (I think that's how that works anyways)
I think so... At the very least, I'm quite sure I shouldn't need to redefine customType, and typeIntstance twice... But I'm at a loss for ideas on how to do this.
nwp
nwp
You could put using customType = MyClass::customType; into the .cpp or just directly use MyClass::customType in the .cpp without another alias.
11:29
I will definitely try your first suggestion. The second suggestion though, I think I've already tried, but the compiler started whinging about unresolved symbols.

I'll take a look though. As the program already compiles, it's just a clean up, but it is a code smell. :[
nwp
nwp
They should really be the same thing.
I'll try both again, for sure.

Cheers for the help. :]
12:21
@Dariusz No.
12:38
Is this the right place to ask about CMake?
Stack Overflow is for questions
Srsly, good chance it got discussed there. If you have no question that could benefit others, fire away
Not every query is easy to find on SO or Google.
We know. So, fire away and we can link you instead :)
Ok so luckily the last thing I tried fixed the problem. Always good to have people around though
It was just path confusion around an include
13:21
Yo, what is the difference between someClass class; and someClass *class = new someClass() ?
nwp
nwp
@Dariusz The second has a memory leak.
humh
the new myClass() ?
nwp
nwp
yup
so why does QT ask me to make all widgets as new QWidget() ?
or does QT use widget destructor to release memory afterwards?
nwp
nwp
Because Qt has a different memory model that works differently than everything else in C++.
13:24
because Qt has tracking built into its QObjects through the parent-child hierarchy it asks you to maintain
nwp
nwp
doc.qt.io/qt-5/objecttrees.html has some info on that
ahh
so if I make my own x = new something(), then at the end I have to destroy it myself, via x.delete/remove delete x or something like tghat?
yeah but most of the time there is no reason for new anything
13:45
fascinating
thanks!
so if i do
object x;
do I do object x or object x(); ? or object x(someArg);
nwp
nwp
14:19
object x(); is a function declaration. It's a nice trap called "most vexing parse".
I would recommend you never use new because then you don't need to worry about delete. Of course Qt is incompatible with good code so you can't always do that, but do it as much as you can.
Also consider using braces to initialize objects. object x; object x{}; object x{args}; are all fine and do what is expected. Unless you are weird and expect std::vector<int> v{1, 2}; to not make a vector containing a 1 and a 2 in that order (because std::vector<int> v(1, 2) doesn't).
interesting
what about header declarations
if I have header
private:
class something;

do I then init it the same way in cpp as something = class() ?
nwp
nwp
something s; seems natural. Possibly followed by {args}.
humh
so with header in past when I used someClass *something, cpp : something = new someClass(), now I do in header someClass something, cpp ; something = someClass() ?
nwp
nwp
14:35
Ah, I misunderstood your question.
hmmm?
nwp
nwp
extern something s; in the header and something s{args}; in the .cpp.
extern humhhh
nwp
nwp
actually scratch that, that was wrong
class something; extern something s; in a header where you don't want to #include "something.h" is totally fine.
im more confused
ok in past I had sometyhing like
.h
fileManager *myFileManager
.cpp
myFileManager = new fileManager(this)
do I do it the same way without the pointer?
nwp
nwp
14:42
That should fail to link due to multiple definitions of fileManager *myFileManager.
It doesn't cause a problem as long as you don't put #include "fileManager.h" in 2 .cpps.
nwp
nwp
15:04
Doing the same without pointers depends on when this is available and when you need it. If it is static you can go the extern route. If it is dynamically created you might be able to construct it without this and then call myFileManager.set(this); later.
Otherwise at least leave out the new and use std::make_shared instead.
mm interesting, thanks ! WIll try to learn & understand it
nwp
nwp
Oh, before std::make_shared try if std::make_unique is good enough for your purposes.
15:32
mm thanks, will try reading up on them !
also
if I want to init struct
in a map
can I do this map[key] = struct() ?
nwp
nwp
I would prefer map[key] = {};, but yours should be fine too.
map[key];
oh interesting thanks!
nwp
nwp
@sehe That doesn't do the same thing when the key already exists in the map.
{} means it will use default value/constructor ?
15:36
@nwp But if it does, initializing it is not possible
nwp
nwp
@Dariusz Yes, it's called "value initialization" and does things like make int be 0.
interesting thanks!
was not sure
nwp
nwp
@sehe Why not? What do you mean?
If it already existed that doesn't initialize, but assign
Depending on the mapped type that might "end up" similar, but it's not the same
if(auto it = map.find(key); it!=map.end()){
    it.second = {};
} else {
    map.insert(std::make_pair(key, struct()));
}
15:40
Now it's merely a roundabout way to do map[key]={};
Also, possibly less efficient depending on the type of key (consider at least emplace)
or std::move on key during insert
still risks being less efficient depending on the weather I suppose (value_type being pair<const K, V>)
nwp
nwp
@sehe nice typo
Looked at it really long. What am I missing?
nwp
nwp
weather whether
15:52
weather is correct
It was chosen to represent fickle fickle optimizer limitations.
nwp
nwp
True. Somehow efficiency depending on weather looked incorrect to me.
ok one more question, if I have function, and I do the someClass myClass;
when function ends, the memory gets released and that myClass gets deleted correct? Like any local variable/etc?
nwp
nwp
Yes.
mm allright, thanks!
nwp
nwp
someClass can still screw something up, but at least the bug is not in your function.
15:56
:- )))
 
5 hours later…
20:34
Hey masters, ok this is silly one, but I have 2 loops inside each other, how can I calculate the loop index offset in array? is it loop1Index * (loop2Index+something) ? I keep getting lost with these transforms :- (
std::vector<int> myItems(size*3)
for(int sizeX=0;sizeX<size;++sizeX)
     (int sizeY=0;sizeY<3;++sizeY){
           myItems[sizeX*sizeY+sizeY] = 1; // ??
20:48
nee I think I got it, darn I hate that equation always mess it up
I'd have to recommend writing a function like template <typename T> void set_2d(std::vector<T>& vector, int x, int y, T value) { ... } and similarly for get_2d. Might also be a good idea to have a index_from_2d(int x, int y). Or you could write a wrapper around std::vector
:O
Id love to but templates are still black magic to me :- )
Im barearly reading them as is hah
but defnititely on my todo - must have list. I keep getting these equations everywhere lately
any1 else wishes that there was a mode to C++ that u could say *1000 every item, so that a piece of text "helloWorld" would weight 100mb, so that when we start learning we hit wall of memory limits and then we start troubleshooting it and learning on memory managment/proper object creation
because holy crap I have memory leaks everywere.
That's one reason why embedded development is really fun. I had a class where there wasn't enough memory for printf or malloc. Sadly I couldn't use C++ :(
21:04
I have function now where I import fbx geometry, but I dont import it, just read file via sdk/ and then close it all. Magically my app goes up 170mb in ram every time I placebo load something
@Dariusz I'd still absolutely recommend you make an index_from_2d. That makes it much more readable myItems[index_from_2d(x, y)] = 1;
intex_from_2d as in template?
No, index_from_2d is simple enough that it doesn't have to be a template. You can write int index_from_2d(int x, int y, int maxX) { return x + y * maxX; } (forgot, needs a maxX)
oh
I see, nice ! yea I can totally have utility function like that ! :D thanks
That way you never have to remember the actual indexing logic, you can just use the function
nwp
nwp
21:06
@Dariusz Well, you should know by now how to fix it.
I wouldn't trust myself to get the indexing logic right all of the time
true
but its kinda good, as I keep re-learning it, eventually I'll know and advance beyond that hopefully.
Just frustrating at times haha
Yay I fixed my memory leak ! I was going from 35 mb to 200-300-600-1000 etc. Now I'm from 35 to 350 when loaded and down to 35 :D Hihihihihihih my 1st mem leak fix :D
Ok another one memory related
.h
vector<myStruct> _data;

cpp
void function(){
     _data.resize(100)
     for(int x=0;x<100;++x){
         myStruct tmpStr; // << this allocated memory in this function location
	 _data[x] = std::move(tmpStr) // this should move the memory from above allocation to _data vector. Releasing/NULL'ing the tmpStr variable?

    }
}
is this correct?
If that caused a memory leak, then your myStruct probably didn't follow the Rule of 3/5/0
no that was not it
that was // memory leak weas becase I created fbx importer in function and never destroyed it
what is rule of 3/5/0?
nwp
nwp
@Dariusz Looks ok memory-wise. Can probably be done a bit simpler.
21:13
do I need to do delete tmpStr;
at the end to release the tmpStr ?
nwp
nwp
You only delete what you got from new. Which is the reason you don't use new.
oh I see
so do I do anything to the tmpStr?
nwp
nwp
Like what?
But probably the answer is still "Looks ok memory-wise. Can probably be done a bit simpler."
not sure, I defined it but never delete, only move it content away ?
nwp
nwp
It's called automatic storage. C++ will automatically get memory from somewhere and automatically clean it up, even if you use return or throw exceptions. It's not your problem.
21:18
strange
so the
myStruct tmpStr;
vector = std::move(tmpStr)
// the tmpStr will be automatically cleared/freed?
nwp
nwp
tmpStr will automatically be destroyed when its scope ends which is at the next }. std::move has nothing to do with it.
oh
humh
nwp
nwp
Some people consider } the most powerful feature in C++.
so ints curious that the fbx importer library did not get auto destroyed after the function ended
I guess it does not have destructor to do it when function ends for some reason o.O
Um are there people/work discipline that take already finished code and then "re-Code-it" correcting all syntaxes/refs/pointers/etc?
nwp
nwp
The library should tell you that. Sometimes libraries are bad and require you to write library_free_the_things();. In that case you write a little class that creates the framebuffer in the constructor and does library_free_the_things(); in the destructor so the badness of the library does not infect your code. Sometimes you can use std::unique_ptr with a custom deleter for that.
21:24
mm fascinating, thanks!
nwp
nwp
I don't think re-coding is a popular activity. People usually call it refactoring where they replace pieces until the code is good enough. Ideally with automatic tests that tell you when your refactoring broke something.
I see, thanks!
22:22
Humh
I have an odd idea
I would like to multithread some loop
using pragmamp perhaps
openMP*
nwp
nwp
Why would you use openmp?
for (int x =0;x<size;++x){
struct val;
getValA(val); // run cp1
getValB(val); // run cp2
getValC(val); //run cp3
getCalD(val);//run cp4
outVal[valId] = val; // wait itll above finish - pass value
valid++;
now I though it would be nice if I can sell all of the valA/b/c/d to different threads, and once they finish send them down to outVal[valiD] = val
why openmp, no reason, just something I was introducet to in past, feels easy to run as its just # command and off to the race so quick/easy I suppose?
nwp
nwp
The major and possibly only advantage of openmp is that you can use it for C++ code as well as fortran and some others. I don't see you needing that.
what should I use ?
nwp
nwp
std::async for the start. Maybe std::thread later.
nwp
nwp
The thing is that this is not a good place to use multithreading.
what do you mean ?
@nwp I'd say the single biggest advantage of OpenMP is that it's easy to graft onto existing code, with little or no change to the logic.
nwp
nwp
@Dariusz The point of multithreading is improving performance by doing multiple things at once. If you can run multiple independent calculations that can be a win. However, creating threads and synchronizing them with each other costs performance.
well
yep
I guess thats what I struggle now with, the way I do my function
nwp
nwp
22:30
Your independent calculations are so tiny and the overhead of creating threads and synchronizing them is so huge that it is a big net loss.
for (int x=0,x<100;++x){
   if(some[x].type = xx){
       struct some;
       _container[count] = some;
       count++;
    }
}
as I have a filter and not all items in a loop are of interest, but I plan to put them in array in correct order. I only need specific ammount of index offset for the _container
so I use counter inside to count that offset
I've updated function
well the getValA/B/C can be large functions, IE loop over 2 mil items, so they can all be multithreaded even if I wait for some lazy threads, 2 of them will be slow 2 of them will be fast
yeah I have to figure out how to offset my count index for multithreading, then I can multithread entire branch of loop
that would speed up stuff a lot
ok this c++ thread stuff is a bit whh... Is this how I should pass it ?
std::thread gV(&myClass::myFunction, tmpGeo, workingMesh);
?
coz I tried that and
std::thread gV(&myFunction, tmpGeo, workingMesh);
and everything errors
std::thread gV(myFunction, tmpGeo, workingMesh);
nwp
nwp
22:49
As I said, go with std::async first.
It is much easier when it comes to running a function in a thread and getting the value later.
Also you should be aware of what a race condition is and that multithreading is very difficult.
async looks even harder than thread o.o
nwp
nwp
It isn't. You just write auto result = std::async(std::launch::async, &the_function, the, arguments);.
Later when you need the result you do use_the_result(result.get());. That's it. Besides watching out for race conditions.
what header do I include for it?
nwp
nwp
<future>
nwp
nwp
22:54
Try it at least once so you can say you used the future of C++.
no matching constructor :- (
can I pass a pointer/reference via it?
nwp
nwp
You pass whatever the_function takes.
possibly with an object if the_function happens to be a member function
@nwp member function ie class member? how do I pass that ? &myclass::function ?
nwp
nwp
Here is an example using a member function.
Regular function is the same, just without the class:: part and the object.
Note that it makes a copy of the arguments in order to avoid race conditions and other life time issues. You can pass &s instead of s, but you better make sure s stays valid and nobody else uses s while the other thread is running. Which is not always trivial.
I think I've got something like this
skipping missing }; on 1st struct, yep it errors @_@
nwp
nwp
23:08
Well, you forgot the ; and result is defined multiple times and you didn't pass an object for the member function.
That last one probably got you.
what did I not pass?
I passed K1 and K2
nwp
nwp
You did, but you cannot call S::compute_the_answer with only K1 and K2. It requires an S and you didn't give it one.
O_O
I just noticed that s
so if I call from class to class
what do I pass
&class?
instead of s?
I tried passing this/class &class/&this/eh nope that async is above my comprehention lol
nwp
nwp
Same as outside.
auto result = std::async(std::launch::async, &S::compute_the_answer, this, K1, K2); would work from inside a member function.
it did work with Qt Concurent tho :- D
nwp
nwp
23:17
Ignore the red squigglies. Intellisense is a bit stupid. Try to compile and look at the error message.
well fuck
curse you ide!
so if I need 4, then I jsut fo result 1/2/3/4/5 and then result1/2/3/4.get() ?
to synchronize them all?
nwp
nwp
That or put them in an array or vector.
The type that is returned is std::future<type_of_thing_that_function_returns>.
they are all voids
I just need them to finish runing
nwp
nwp
Well, std::future<void> it is.
instead of auto result?
nwp
nwp
23:20
yup
only if you want to put them in an array
otherwise auto is easier
Use .wait() instead of .get() though. Because void is special.
but .get() worked
nwp
nwp
Well, you do know about race conditions, right?
they all work on different data
4 different arrays/data sets
nwp
nwp
None of them modify anything in this?
nwp
nwp
23:24
Hmm, don't know why it crashed then.
I pass reference, they read data, they generate new data in their own functions and then they go to referenced struct and just sets different struct.vertex/struct.normals to different arrays
nwp
nwp
Why is result4 a different color?
its ide auto coloring, they all a bit different c olors
yea that async with .get did not speed up, 1 core = 75 seconds, 4 core asunc = 72 seconds, qt concurent = 5.6 seconds
I think I will be better off if I encapsulate entire loop function in a thread, so 1 thread = 1 loop, like openMP but I have to find a way to synchronize counter
nwp
nwp
There is a chance that that FBXimporter is using an internal cache which causes a race condition or something. The library documentation might say something about thread-safety.
If counter is something simple like an int you can make it a std::atomic<int> and just access it.
humh
this is esentially entire function"light weight one"
int myCount=0;
vector<struct> _data(jobSize)

for(int x=0;x<allNodes;++x){
    if(node[x]=="type"){
	struct tmpData;
        genVert(tmpData,node[x])
	genNorm(tmpData,node[x])
	_data[myCount] = tmpData;
	myCount++
    }
}
I just re-run Qt Concurent test, no idea why but speed was 69 this time, so async 72, single core 75. Damn :- )
the 5.6 result last time must have been a bug lol
nwp
nwp
23:34
Making myCount a std::atomic<int> wouldn't be quite enough here because 2 threads might both do _data[myCount] = tmpData; with the same value of myCount and then both increment it which is no good.
yep
thats where I'm stuc, so hmmmmmmmmmmmm
I'm reading on the fbx SDK they say its not thread save
so I don't think I should thread it snap
nwp
nwp
_data[myCount++] = tmpData; should fix that
would that not make item 0 empty?
I can just add +1 to size of vector I guess
let the count start from 1 rather than 0
erase empty item at the end
nwp
nwp
23:37
Huh? Why?
well if you do myCount++, then is it not _data[1] ?
nwp
nwp
no. It's post-increment, meaning the return value of myCount++ will be before it was incremented, so it starts at 0.
If you do _data[++myCount] then it's pre-increment and starts with 1.
oh right
worth a try I think o>o
leme get openMP in,
0
1
2
3
4
5
6
0
1
2
3
0
1
2
3
4
it almost worked :D
will render on openMP maybe there is a lag I can pass
int sum=0;
 #pragma omp parallel for reduction(+:sum)
 for(int n=0; n<1000; ++n) sum += table[n]; perhaps this :O

« first day (577 days earlier)      last day (2500 days later) »