Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For a small 4x4 matrix, I would avoid dynamically allocating memory on the heap ... a simple one-dimensional array that you can index as a 2D array should suffice (i.e., the ordered pair (x,y) value would be <code>matrix_array[COLUMNS * y + x]</code>), especially considering that loading any single value in the array will also cause adjacent values to be stored on the processor's cache-line, speeding up access to any adjacent elements. The cache-loading can happen with heap-allocated memory as well, but the main reason to avoid heap allocation if possible for small matricies is that many sequential math operations will require you to return a temporary, and without r-value references, you're going to end up doing a lot of calls to <code>new</code> and <code>delete</code> inside the copy-constructors of those temporaries which will slow things down tremendously compared to quickly allocating memory on the stack.</p> <p>Secondly, I would suggest you go with a templated approach, as this will let your define you matrix for not only plain-old-data-types like <code>double</code>, etc., but also for any secondary composite types you may decide to define later, or import from another library such as rationals, complex numbers, etc. Whether you decide to add operator overloads is really up to you ... some people do not like it because it "hides" the complexity of what may be happening underneath the hood (i.e, <code>A * B</code> for <code>doubles</code> will be far simpler than <code>A * B</code> for a 4x4 <code>matrix&lt;double&gt;</code>). On the other-hand, it can greatly simplify the amount of code you write for complex math operations.</p>
    singulars
    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.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      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