Such alignment restrictions simplify the design of

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ent space is available, it returns null. New to C? In C, storage on the heap (a pool of memory available for storing data structures) is allocated using the library function malloc or its cousin calloc. Their effect is similar to that of the new operation in C++ and Java. Both C and C++ require the program to explictly free allocated space using the free function. In Java, freeing is performed automatically by the run-time system via a process called garbage collection, as will be discussed in Chapter 10. End We can then use the indexing computation of row-major ordering to determine the position of element of the matrix as ¡ Ò · : 1 2 3 4 int var_ele(var_matrix A, int i, int j, int n) { return A[(i*n) + j]; } This referencing translates into the following assembly code: 1 2 3 4 5 movl 8(%ebp),%edx movl 12(%ebp),%eax imull 20(%ebp),%eax addl 16(%ebp),%eax movl (%edx,%eax,4),%eax Get A Get i Compute n*i Compute n*i + j Get A[i*n + j] Comparing this code to that used to index into a fixed-size array, we see that the d...
View Full Document

This note was uploaded on 09/02/2010 for the course ELECTRICAL 360 taught by Professor Schultz during the Spring '10 term at BYU.

Ask a homework question - tutors are online