Algorithm of dynamic segmented memory allocation