Reputation: 651
I've read this quote in a book:
There is no problem in computer science that can't be solved using another level of indirection.
Can someone explain that? What does "level of indirection" mean?
From what I understood, indirection is a fancy name for using a pointer of a value instead of the value itself. Please clarify this for me.
Upvotes: 50
Views: 22075
Reputation: 121
Great question! I actually came across this term level of indirection
in my database course. The slides for this course does not even provide any information regarding 'indirection' or how to use it, but it challenges students with a question like this:
... suppose the file is unordered by the non-key field DEPTNUMBER and we want to construct a secondary index on DEPTNUMBER with one level of indirection that stores record pointers.
Your understanding mentioned makes the subtle thing clear to me:
From what I understood, indirection is a fancy name for using a pointer of a value instead of the value itself.
Here I attach a picture in the question to illustrate. The so-called level of indirection
is nothing but some blocks of memory containing pointers
, which is a bridge between the indexes
and the data
. So here, instead of having one index for each record in the data file, it uses an aditional layer composed by pointers
, making the indexes between the index file and the level of indirection(block of record pointers) sparse.
And my understanding for this is it offers a good trade-off between memory usage and look-up speed by having a sparse(non-dense) index as well as a dense index for a unordered
data file.
Unfortunately I could not manage to find a good explanation for the term level of indirection
with respect to its implementation for database on the internet while my school's slides is just trash(it does not even cover it but they make questions with it).
Please comment if you have a good source or if I have mistaken with anything here. I would really appreciate that!
Upvotes: 6
Reputation: 12985
"Indirection" is using something that uses something else, in its broadest sense.
So your example, using a pointer of a value instead of the value, fits this definition at one level. The pointer is the something and the value is the something else.
Typically this is something larger in scope:
This last example, perhaps, explains the "why" of it all.
As we work with something we master it and learn how to abstract it to a higher level of abstraction, thus a new level of indirection is needed and we can solve bigger problems faster by offloading some of the work to the new API.
Upvotes: 55
Reputation: 2619
One of the potential big advantages of indirection is reduced coupling. It's another way of saying that things should be compartmentalized appropriately. This often helps significantly with testing, maintainability, and flexibility over the long term.
As an example, if your application needs to read some persisted data, instead of having the specific knowledge of where (and how) to read it scattered all throughout the application, you isolate it (put that reading of data into a method) and then let all of the other parts of your application call that method to get the data instead of each part of the app having to deal with those details itself.
Upvotes: 11