I've got this for my pmm, but it's ugly. Speed is very important, so I tried to make it as simple as possible, but also very fast. I'm kinda dissatisfied with it and not sure it will function as it's supposed to. I'm nowhere near(weeks away) from being able to compile, so I need some reassurance that it's correct before I proceed with development. If anyone can help me simplify it, or point out a bug, I'd greatly appreciate it.

Pages are managed starting at 1(ie first page is identified with 1, not 0).Code:unsigned int get_pages(int pages) { int i,j = 0; for(i = reserved_low_pages + 1;i + pages <= total_pages;i += (j + 1)) for(j = 0;j <= pages;j++) if(j == pages) { alloc_pages(i, pages); return i; } else if(check_page(i + j)) break; panic("Out of memory!"); return 0; }