exception Out_of_memory;; let free_pages = Array.make page_number 0;; let clear_page page_nb = let offset = page_nb * page_size in Array.fill memory offset page_size 0;; let find_modulo f modulo from = let stop = from + modulo in let rec find k = if k < stop then let k' = k mod modulo in if f k' then k' else find (k+1) else raise Not_found in find from let next_page = ref 0;; let new_page () = try let is_free p = free_pages.(p) = 0 in let page_nb = find_modulo is_free page_number !next_page in next_page := page_nb + 1; free_pages.(page_nb) <- 1; clear_page page_nb; page_nb with Not_found -> raise Out_of_memory;; |