Hi,
I'm reading and trying to understand the pstorage
API. And I found a code snippet in pstorage_register
(SDK 6.0.0).
do
{
page_count++;
if (total_size > PSTORAGE_FLASH_PAGE_SIZE)
{
total_size -= PSTORAGE_FLASH_PAGE_SIZE;
}
else
{
total_size = 0;
}
m_next_page_addr += PSTORAGE_FLASH_PAGE_SIZE;
}
while (total_size >= PSTORAGE_FLASH_PAGE_SIZE);
Why use iteration here? Does this style have higher efficiency than code like this?
if (total_size % PSTORAGE_FLASH_PAGE_SIZE == 0)
page_count = total_size / PSTORAGE_FLASH_PAGE_SIZE;
else
page_count = total_size / PSTORAGE_FLASH_PAGE_SIZE + 1;