/**
* Find block of free frames with required length in managed memory
* unsing Next Fit technique.
* \param count Length of required block in frames
* \return Index of start of the found block or ENOMEM if block was not found.
*/
static int find_next_fit(int count)
{
if(count>free_frames_count)
{
return ENOMEM;
}
static int next_index = 0;
const int begin_index = next_index;
int limit = num_frames;
int found = 0;
for(next_index=0; next_index<limit; next_index++)
{
if(bitmap[next_index]==FREE_FRAME)
{
found++;
if(found==count) {
return next_index-count+1;
}
} else {
//This block isn't large enough
found = 0;
}
}
//are we searching from beginning?
if(begin_index!=0)
{
//search from beginnig
next_index = 0;
return find_next_fit(count);
}
return ENOMEM;
}