Added required memory size calculation