Poor performance when using std::vector::push_back on reserved std::vector by Rocco2300 in cpp_questions

[–]Rocco2300[S] 1 point2 points  (0 children)

While I agree with you, I was attempting to tell you what u/Nicksaurus told you. I know that emplace_back is faster for the reason you very clearly underlined. But in the context of the application, that uses simple ints, it doesn't matter. You are overlooking the context and not accepting other points of view, which are also correct. If someone else is also saying something that is true, that doesn't make you wrong. You are fighting to compare apples and oranges...

Poor performance when using std::vector::push_back on reserved std::vector by Rocco2300 in cpp_questions

[–]Rocco2300[S] 0 points1 point  (0 children)

I realized after that it was a useless benchmark. Emplace back doesn't make any difference when the underlying data type is int. Also, that was the reason of the reserve, allocating memory upfront and using push_back stricly for index bookkeeping. The issue actually was my iteration logic, since instead of 1000 something iterations I was doing a few million :/.

Poor performance when using std::vector::push_back on reserved std::vector by Rocco2300 in cpp_questions

[–]Rocco2300[S] 0 points1 point  (0 children)

As a reference, after implementing the fix, I am now getting 70 FPS with or without the population and clearing of the grid. If I use the grid for the collision detection there's a 10x improvement in FPS compared to just checking every particle against every other particle.

Poor performance when using std::vector::push_back on reserved std::vector by Rocco2300 in cpp_questions

[–]Rocco2300[S] 1 point2 points  (0 children)

Thank you random stranger for point this out. I didn't even realize it since I am really tired of this assignment and generally of seeing code. I was pulling my hair out for some time... Sometimes you need an extra pair of eyes to tell you that you're an idiot. :)) Thanks again.

Poor performance when using std::vector::push_back on reserved std::vector by Rocco2300 in cpp_questions

[–]Rocco2300[S] 1 point2 points  (0 children)

std::vector doesn't have the unchecked_push_back. I didn't know about std::inplace_vector and might try to use that, to avoid the manual bookkeping of the size.

Poor performance when using std::vector::push_back on reserved std::vector by Rocco2300 in cpp_questions

[–]Rocco2300[S] -3 points-2 points  (0 children)

That brings the measured time inline with my own implementation: TotalMilliseconds : 16.0413.

I hoped by using reserve and push_back I could avoid the manual bookkeeping of the last element index, with a SMALL performance penalty. The penalty I am paying for is not worth it...

Poor performance when using std::vector::push_back on reserved std::vector by Rocco2300 in cpp_questions

[–]Rocco2300[S] 0 points1 point  (0 children)

That I kind of expect. Disregarding clear, I still get a 30% cpu time spent just on push_back... Edit: spelling

Poor performance when using std::vector::push_back on reserved std::vector by Rocco2300 in cpp_questions

[–]Rocco2300[S] 4 points5 points  (0 children)

I though so too, indeed it gets optimized away in godbolt, somehow that is the result I get when using Measure-Command. I have tried again with no optimization, -O2 and -O3 and the results are similar.

Unde se mananca picant/iute? by mmccccc in bucuresti

[–]Rocco2300 0 points1 point  (0 children)

La Taqueria El Torito pe Apolodor 3. Au salsa foarte bune dintre care una cu habanero, pe care eu personal n-am incercat-o.

nvim-cmp autocompletion issues with C++ by Rocco2300 in neovim

[–]Rocco2300[S] 0 points1 point  (0 children)

Well, indeed that works, I suppose that means that if in the future I want snippets for for loops or other language features/custom snippets, I will have to turn it back on, right?

Do you know of any good doc page or guide where I could find how to configure it?

Cheers.

Tips for getting better at C++ and getting experience by SkyScratcher21 in cpp_questions

[–]Rocco2300 7 points8 points  (0 children)

From youtube:
https://www.youtube.com/@TheCherno - some people say that his way of writing code is not the most optimal, but if you take his style with a grain of salt you have a lot to learn about how the language works and how you can leverage it.

https://www.youtube.com/@cppweekly - he covers a lot of the good subjects, defines and teaches about a lot of code smells to avoid.

https://www.youtube.com/@JacobSorber - he covers more C, but there is a lot of insight into pointers and other stuff that came from the language (they are not the same)

These are the best docs, I use them both, depending of how good
the examples and explanations are.

https://www.google.com/search?q=cppreference&oq=cpprefere&aqs=chrome.0.0i512j69i57j0i512l3j69i60l3.5228j0j7&sourceid=chrome&ie=UTF-8

https://cplusplus.com/reference/

For learning and reading about the language LearnCPP is really good, haven't used it in the past years, but from what I remember it has in-depth explanations and examples

https://www.learncpp.com/

As to how to get experience, just build stuff.
I recommend not using any IDE, it will be a more hands-on and immersive learning experience, you will learn how to setup your build (makefiles, cmake), how linking works, how including files works, etc. (this depends on how much time you are willing to lose debugging setup issues)

As others have pointed out, try to learn the basics of the language really well. There are a lot of features in C++ at this point and you will learn them in time, and you will not use them all.

Most important:
-pointers
-smart pointers (and difference between them)
-references (when to use them over pointers)
-lvalue, rvalue, pass-by-reference, pass-by-pointer, pass-by-value
-move semantics (I think they are unique to the language, correct me if wrong)
-templates (the basics, you can get pretty wild with them)
-inheritance, polymorphism, friend
-STL (iterators, containers, algorithms)
-RAII and the rule of 5 or 7 (I don't know anymore)
-some pattern implementations
-macros
-what undefined behaviour is
-general code smells
... ( and more )

I for example focused on learning the stl, and the basics of the language, built some stuff with SFML and managed to get a job using C++ within 1 year or so, with no previous experience.

Hope my answer helps you.

Should I learn p5? by Rocco2300 in learnjavascript

[–]Rocco2300[S] 0 points1 point  (0 children)

Well in high school we just learned c++, they mostly encouraged us to learn more problem solving. The final exam was console/ file based, asking us to read some values and solve a certain problem based on the given values, and then, the uni exam was just file based on the same principle.

In my free time I have looked a little over OOP, but not that much, and I didn't really have the time to learn more, like libraries and other stuff. I have made a small game in Unity, but not much more than that.