I was reading this pull request on dablooms
To top it off, Murmur doesn't return the hash value on the stack/registers but writes it directly to a provided buffer. This makes it exceedingly easy to fill the bloom->hashes buffer with a lot of random data and perform the modularization incrementally.
for (i = 0; i < bloom->nsalts; i++, hashes += 4) {
MurmurHash3_x64_128(key, key_len, bloom->salts[i], hashes);
hashes[0] = hashes[0] % bloom->counts_per_func;
hashes[1] = hashes[1] % bloom->counts_per_func;
hashes[2] = hashes[2] % bloom->counts_per_func;
hashes[3] = hashes[3] % bloom->counts_per_func;
}
I recently noticed that some libraries (at least in C++, my knowledge is pretty limited as I'm quite a newbie) seem not to return values but to instead expect an output argument on which they will write the result. I'm more used to see thing like this:
Matrix leftOperand = { /* some values */ };
Matrix rightOperand = { /* some values */ };
Matrix result;
result = multiplyMatrices( leftOperand, rightOperand );
Where result
is the return
value of multiplyMatrices
. But learning to use OpenGL, GLEW and freeglut in my most recent project, I see more often than not calls like this:
Matrix leftOperand = { /* some values */ };
Matrix rightOperand = { /* some values */ };
Matrix result;
multiplyMatrices( leftOperand, rightOperand, result );
I understand what it does, but I find the notation to be odd. However I see that more and more often, and when I saw it 'praised' by the author of above's pull request, I thought there might be a good reason to do that.
So in my quest to write less bad and smelly code, I'd like to know if this is good practice. I assume it must be for performance reasons, but I don't see clearly if pushing/poping from the stack is slower than writing directly to a given memory address.
I'm looking for some guidelines on the reasons to use one way over another.