simulate memory_allocate algorithm