Improvement of the algorithm in alloc and allocextend