This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

NRF51822 API efficiency

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;
Related