The body of this procedure consists of a “for” loop to search the “map” array until either:
the end of the list of available resources is encountered; or
an area large enough to honour the current request is found;
The “for” statement initialises “bp” to point to the first element of the resource map. At each succeeding iteration “bp” is incremented to point to the next “map” structure.
Note that the continuation condition
“bp-m_size” is an expression, which becomes zero with the sentinel is referenced. This expression could have been written equivalently but more transparently as “bp-
m_size
0”.
Note also that no explicit test for the end of the array is made. (It can be shown that this latter is not necessary provided CMAPSIZ, SMAPSIZ 2 * NPROC !)
If the list element defines an area at least as large as that requested, then ...
Remember the address of the first unit of the area;
Increment the address stored in the array element;
Decrement the size stored in the element and compare the result with zero (i.e. was it an exact fit?);
In the case of an exact fit, move all the remaining list elements (up to and including the sentinel) down one place.
Note that “(bp-l)” points to the structure before the one referenced by “bp”;
The “while” continuation condition does not test the equality of “(bp-l)-m_size” and
bm-m_size !
The value tested is the value assigned to
“(bp-m_size” copied from “bp-
m_size”.
(You are forgiven for not recognising this at once.);
Return the address of the area. This represents the end of the procedure and hence very definitely the end of the “for” loop.
Note that a value of zero returned means “no luck” This is based on the assumption that no valid area can ever begin at location zero.