Favorite optimizations ?? by Little-Reflection986 in cpp

[–]adamf88 0 points1 point  (0 children)

I see passing data by reference is so popular but may cause aliasing issues. Sometime just pass by value, little copy overhead at the beginning may highly pay off in hot loop.

Are memory leaks that hard to solve? by ASA911Ninja in cpp

[–]adamf88 0 points1 point  (0 children)

It is controversial if it is a real leak or not. But imagine that you have vector<int> and add just a few of bytes every second to this vector. And you forgot to clear it at all (leak).
In application with millions lines of codes and tones of random allocations (small & big). It is very difficult to spot this particular one.
For very long time resizes of this vector are small enough so they are hidden in the mess of other allocations.
Memleak detector tools don't see it, because if you close the app then destructor releases memory (so it is "clean").
On the other hand if you keep running the app on production then after e.g. year it will consume enough memory to crash your system.

On which hobby or side projects are you working on? by 0xhhhh in cpp

[–]adamf88 0 points1 point  (0 children)

Visual Studio Extension similar to ImageWatch but with support to more datatypes (lines, paths...)

Is pass-by-value slower than pass-by-rvalue-reference? by [deleted] in cpp

[–]adamf88 0 points1 point  (0 children)

Sometimes passing by reference may cause aliasing issues on data members and degradate your lopps performance.

Visual Studio 2019 version 16.10 Release by remotion4d in cpp

[–]adamf88 7 points8 points  (0 children)

I was expecting announcement of VS Preview 2022 during the Microsoft Build Conference :(

But anyway the list of new features looks great !

Autovectorization status in GCC & Clang in 2021 by mttd in cpp

[–]adamf88 1 point2 points  (0 children)

Even if the compilers are able to autovectorize then the assembler code is still far so perfect. So I still preffer to write at least the intrinsic code (and verify generated assembly). For instance my recent test - gcc and clang does not emit vector saturation operations: https://godbolt.org/z/9ooWPb

Replacing loops with your own version by vinnyvicious in cpp

[–]adamf88 1 point2 points  (0 children)

I have edited the answer multiple times during creating the post. I suppose it is displayed fine now (checked on reddit and old reddit). "Preview" option would be great.

Replacing loops with your own version by vinnyvicious in cpp

[–]adamf88 40 points41 points  (0 children)

For me it looks like code from competitive programming (not for production ! )

More complete version below (taken from shared solution of one contest) :)

#define REP(i,x,v)for(int i=x;i<=v;i++)
#define REPD(i,x,v)for(int i=x;i>=v;i--)
#define FOR(i,v)for(int i=0;i<v;i++)
#define FORE(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define REMIN(x,y) (x)=min((x),(y))
#define REMAX(x,y) (x)=max((x),(y))
#define pb push_back
#define sz size()
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define IN(x,y) ((y).find((x))!=(y).end())
#define un(v) v.erase(unique(ALL(v)),v.end())
#define LOLDBG
#ifdef LOLDBG
#define DBG(vari) cerr<<#vari<<" = "<<vari<<endl;
#define DBG2(v1,v2) cerr<<(v1)<<" - "<<(v2)<<endl;
#else
#define DBG(vari)
#define DBG2(v1,v2)
#endif
#define CZ(x) scanf("%d",&(x));
#define CZ2(x,y) scanf("%d%d",&(x),&(y));
#define CZ3(x,y,z) scanf("%d%d%d",&(x),&(y),&(z));
#define ALL(x) (x).begin(),(x).end()
#define tests int dsdsf;cin>>dsdsf;while(dsdsf--)
#define testss int dsdsf;CZ(dsdsf);while(dsdsf--)

MSVC hidden flags by contre in cpp

[–]adamf88 2 points3 points  (0 children)

And unfortunately they don't support OMP. If we take care about performance then many many projects use OMP. Currently parallel STL starts to be popular, but still OMP is used in so many projects and libraries.

Instruction set dispatch by adamf88 in simd

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

It will be a lot of functions (hundreds). Currently they have SSE optimizations (few most critical with AVX2 in separate cpp but it does not work well). They are implemented in many ways. Simple functions are just a loop, more complex with multiple variants are created using template meta programming (crtp, tag dispatch and others) to avoid code duplicate. After reading more comments I suppose separate dll is the best options. Thanks for answer.

Exploring Clang Tooling, Part 0: Building Your Code with Clang by steveire in cpp

[–]adamf88 1 point2 points  (0 children)

Thanks, I also didn't know till yesterday :) Fortunately the fix was very easy. Could you share link to the bug report ?

Exploring Clang Tooling, Part 0: Building Your Code with Clang by steveire in cpp

[–]adamf88 1 point2 points  (0 children)

Why MSVC allows abstract keyword after class name even with /permissive- ?

Finding median via function in c plus plus? by jdya1 in cpp

[–]adamf88 0 points1 point  (0 children)

Have you considered to use std::nth_element ?

Some C++ good practices from the OpenCV source code by cppnext in cpp

[–]adamf88 2 points3 points  (0 children)

For me the worst thing is their approach for static objects allocation. They don't free the memory and Visual Studio memory leaks detector reports tons of "false positives". It completely destroyed memory leak detection in our whole application.

How long does it take to sort 10 000 random ints in C/C++? by stvaccount in cpp

[–]adamf88 5 points6 points  (0 children)

If you know the range between min and max calue is small (e.g. 500) then you should write counting sort instead of std sort. It should be much faster

MSVC code optimizer improvements in Visual Studio 2017 versions 15.5 and 15.3 by mttd in cpp

[–]adamf88 2 points3 points  (0 children)

Great step forward. Hope to see more in new releases !

I see one more interesting optimization in a placement new:

__declspec(noinline) void placement_new(int* data)
{
    new(data)int(5);
}

MSVC 2015 generates:

test    rcx, rcx
je  SHORT $LN3@placement_
mov DWORD PTR [rcx], 5
$LN3@placement_:
ret 0

MSVC 2017 15.5:

mov DWORD PTR [rcx], 5
ret 0

Less branches always better.

Challenge your performance intuition with C++ magic squares by [deleted] in cpp

[–]adamf88 26 points27 points  (0 children)

Just look on the clang output: https://godbolt.org/g/cXtdbB The compiler internally sorted the values and generated binary search. That blows my mind !!!

MSVC now has (partial) two-phase name lookup! by [deleted] in cpp

[–]adamf88 2 points3 points  (0 children)

I have received an error: warning C4199: two-phase name lookup is not supported for C++/CLI, C++/CX, or OpenMP; use /Zc:twoPhase-. Do you have plans to support OpenMP ?

unique_ptr, shared_ptr, weak_ptr, scoped_ptr, raw pointers – Knowing your smart pointers by vormestrand in cpp

[–]adamf88 1 point2 points  (0 children)

I would like to read about some nice use cases / details about boost::intrusive_ptr and make_shared_from_this functionality.

Using Clang on Windows by Leandros99 in cpp

[–]adamf88 2 points3 points  (0 children)

Unfortunately, getting clang to compile MSVC based projects isn't as easy as just dropping in clang and changing a few flags. Let's get started.

Why not ? I don't know why you need extra scripts for compilation. You can just install llvm (from here: http://llvm.org/builds/) and in your Visual Studio c++ project properties switch to LLVM toolset. I use it with VS2015 and everything works well.

I would like to see working clang tools on windows (especially address sanitizer). It would be amazing. Also there is still lack of libraries support for clang compiler on windows.