Tuesday, July 24, 2007
Wednesday, June 20, 2007
Alignment
excerpted from 3.10 Computer Systems
Reason: Many computer systems place restrictions on the allowable addresses for the primitive data types, requiring that the address for some type of object must be a multiple of some value k (typically 2, 4, or 8). Such alignment restrictions simplify the design of the hardware forming the interface between the processor and the memory system.
Note: the IA32 hardware will work correctly regardless of the alignment of data. However, Intel recommends that data be aligned to improve memory system performance.
Alignment with Linux: Linux follows an alignment policy where 2-byte data types (e.g., short) must have an address that is a multiple of 2, while any larger data types (e.g., int, int *, float, and double) must have an address that is a multiple of 4.
Note: a multiple of 2 means the least significant bit of the address of an object of type short must equal 0. Similarly, any object of type int, or any pointer, must be at an address having the low-order two bits equal to 0.
Alignment with Microsoft Windows: Microsoft requires a stronger alignment requirement - any k-byte (primitive) object must have an address that is a multiple of k. In particular, it requires that the address of a double be a multiple of 8.
Note: malloc must be designed so that they return a pointer that satisfied the worst-case alignment restriction for the machine it is running on, typically 4 or 8.
For structures, the compiler may need to insert gaps in the field allocation to ensure that each structure element satisfies its alignment requirement. The compiler must also ensure that the structure has some required alignment for its starting address. In addition, the compiler may need to add padding to the end of the structure so that each element in an array of structures will satisfy its alignment requirement.
Matlab: Diminishing the Size of a Matrix
Diminishing the Size of a Matrix
You can delete rows and columns from a matrix by assigning the empty array [] to those rows or columns. Start with
A = magic(4)
A =
16 2 3 13
5 11 10 8
9 7 6 12
4 14 15 1
Then, delete the second column of A using
A(:, 2) = []
This changes matrix A to
A =
16 3 13
5 10 8
9 6 12
4 15 1
If you delete a single element from a matrix, the result isn't a matrix anymore. So expressions like
A(1,2) = []
result in an error. However, you can use linear indexing to delete a single element, or a sequence of elements. This reshapes the remaining elements into a row vector:
A(2:2:10) = []
results in
A =
16 9 3 6 13 12 1
You can delete rows and columns from a matrix by assigning the empty array [] to those rows or columns. Start with
A = magic(4)
A =
16 2 3 13
5 11 10 8
9 7 6 12
4 14 15 1
Then, delete the second column of A using
A(:, 2) = []
This changes matrix A to
A =
16 3 13
5 10 8
9 6 12
4 15 1
If you delete a single element from a matrix, the result isn't a matrix anymore. So expressions like
A(1,2) = []
result in an error. However, you can use linear indexing to delete a single element, or a sequence of elements. This reshapes the remaining elements into a row vector:
A(2:2:10) = []
results in
A =
16 9 3 6 13 12 1
C++ Design Tricks
1. Place the copy constructor in the private section to disallow call by values. (Recall the mechanisms of passing by value for objects)
2. Generally, if a destructor is necessary to reclaim memory, then the default for copy assignment and copy construction are not acceptable.
2. Generally, if a destructor is necessary to reclaim memory, then the default for copy assignment and copy construction are not acceptable.
Tuesday, June 19, 2007
Chapter 1. Introduction
Direct memory access (DMA) : the data travels directly from disk to main memory, without passing through the processor.
Subscribe to:
Posts (Atom)