Note that there are some explanatory texts on larger screens.

plurals
  1. POIs it better to return values or to write them directly on a given output argument?
    primarykey
    data
    text
    <p>I was reading this <a href="https://github.com/bitly/dablooms/pull/19" rel="nofollow" title="Some performance tweaks">pull request on dablooms</a></p> <blockquote> <p>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.</p> </blockquote> <pre><code>for (i = 0; i &lt; bloom-&gt;nsalts; i++, hashes += 4) { MurmurHash3_x64_128(key, key_len, bloom-&gt;salts[i], hashes); hashes[0] = hashes[0] % bloom-&gt;counts_per_func; hashes[1] = hashes[1] % bloom-&gt;counts_per_func; hashes[2] = hashes[2] % bloom-&gt;counts_per_func; hashes[3] = hashes[3] % bloom-&gt;counts_per_func; } </code></pre> <p>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:</p> <pre><code>Matrix leftOperand = { /* some values */ }; Matrix rightOperand = { /* some values */ }; Matrix result; result = multiplyMatrices( leftOperand, rightOperand ); </code></pre> <p>Where <code>result</code> is the <code>return</code> value of <code>multiplyMatrices</code>. But learning to use OpenGL, GLEW and freeglut in my most recent project, I see more often than not calls like this:</p> <pre><code>Matrix leftOperand = { /* some values */ }; Matrix rightOperand = { /* some values */ }; Matrix result; multiplyMatrices( leftOperand, rightOperand, result ); </code></pre> <p>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.</p> <p>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.</p> <p>I'm looking for some guidelines on the reasons to use one way over another.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload