Tag Info

New answers tagged

0

The basic approach would be; for each row: Load the entire row into "SIMD register 1" (MMX, SSE, AVX, Neon, whatever) Copy it into "SIMD register 2" Multiply "SIMD register 2" by 0.2 (pity it's not 25%...) Subtract "SIMD register 2" from "SIMD register 1" Shift "SIMD register 2" right by 1 element Add "SIMD register 2" to "SIMD register 1" Store "SIMD ...


1

matrix is a pointer to a 5-element array of double; this means that the type of the expression *matrix is "5-element array of double"; sizeof *matrix will return the number of bytes required by such an object. So we're telling malloc to set aside enough memory for 5 5-element arrays of double, and assign the resulting pointer to matrix. Because of how ...


1

Do you know where the majority of time is being spent? There could be all sorts of ways to speed this up. There's not enough code to know for sure, unless you're specifically asking only about the math. Computers are extremely good at math, so the problem is likely somewhere else than the actual computation of the data. For example, in one toolkit I know ...


2

To me it's always 64. The location of 5,5 is 0+(((5-1)*7)+(5-1))*2= ((4*7)+4)*2= 28*2+4*2= 56+8= 64. When you manually trying to calculate did you by any chance calculated the end address of the element at location 5,5 while you expected it's starting address? It's a common mistake, I'm asking because you didn't post how you calculated it manually. 00 02 ...


0

Here's some code that clearly shows memory layout for arrays. Using a union, for which memory is overlaid for each union member, we can see that values are stored in row-major order. #include <stdio.h> #define N 4*4*4 #define N_2D 8 #define N_3D 4 union multi_d_arrays { int one_d[N]; int two_d[N_2D][N_2D]; int ...


0

In addition to Jules' answer, I would like to add a bit of historical perspective. The counter-intuitiveness of this in C is due to the simple fact: In general, int a[] (length unspecified) is some sort of syntactic sugar in place of int* a Likewise, int a[][] (again, lengths unspecified) is some sort of syntactic sugar in place of int** a. Because the ...


4

You're nearly right, yes. In fact, int a[5][10]; declares 5 arrays each of which contain 10 integers, rater than the other way round. Other than that you're completely right. See http://en.m.wikipedia.org/wiki/Row-major_order for a more detailed description and an explanation of why the order is important.


0

Your suggestion isn't quite right. int A[x][y]; (where 'x' and 'y' are expressions that can be evaluated to a constant at compile time) declares a single block of memory that is xysizeof(int) bytes long, and A[i][j] is translated to a reference to the I*y+jth value in the block. On the other hand, int ** A = new int *[x]; allocates an array of x ...


3

Well, there are many arguments one way or the other. But the most important thing to realize: it doesn't matter (in this case). Performance wise, the drawing (and subsequent rendering of it) will take order of magnitudes longer than the invocation of the right drawing functions. Complexity wise, the drawing code will most likely also crushingly outweigh ...


2

IMHO the first one is in most cases preferable. First, in C# you can rewrite the initialization much shorter as Action[] array = new[]{one, two, thre, four, five, six, seven,eight,nine}; But the real advantage comes when you have to change your actions later, for example, by introducing an additional argument. You then have to change only this line ...


1

Of course there are pro and con effects; if there weren't, the community would long ago have figured them out, and everybody would agree to do always the one and never the other. A switch statement is fine if the things you switch over have only one behaviour. A button does something when clicked, so that seems appropriate. But as soon as the variable ...



Top 50 recent answers are included