
130 CHAPTER 5. SHARED-MEMORY: C
8 * i + j
of the array.
In writing generally-applicable code, we typically don’t know at compile
time how many columns (8 in the little example above) our matrix has. So
it is typical to recognize the linear nature of the internal storage, and use
it in our C code explicitly, e.g.
i f ( adjm [ n∗ i+j ] == 1) {
adjm [ n∗ i +( t o t 1 s ++)] = j ;
The memory allocation issue has popped up again, as it did in the Rdsm
implementation. Recall that in the latter, we allocated memory for an
output of size equal to that of the worst possible case. In this case, we
have chosen to allocate memory during the midst of execution, rather ...