C Programming Question Which of the following exhibit spatia
C Programming Question:
Which of the following exhibit spatial locality: The memory layout of a heap allocated 1D array. Binary search on an array of integers. The sequencing control flow. 3 only 2 and 3 1, 2 and 3 1 and 3 2 onlySolution
A sequence of references is said to have spatial locality if things that are referenced close in time and also are close in space.For example, If any particular storage location is referenced at a particular time, then it is likely that nearby memory locations to it will be referenced in the near future.
1. \"The memory layout of a heap allocated 1D array.\" Heap memory allocation exhibits poor spatial locality.Although dynamic memory allocation called pool allocation exhibits spatial locality.
2. \"Binary search on an array of integers\" => Once the search range in a binary search has been reduced down to a size less than or equal to orignal search range, the subarray that remains to be searched will occupy one or two cache lines and are later referenced close together in time.Thus, it exhibits spatial locality.
3. \"The sequencing control flow\" => Computation regrouping in cache is difficult to automate for programs with sequencing control structures
Correct Ans : E (2 only)

