From the course: IoT Foundations: Operating Systems Fundamentals

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

First fit algorithm

First fit algorithm

From the course: IoT Foundations: Operating Systems Fundamentals

Start my 1-month free trial

First fit algorithm

- [Instructor] We know that we can allocate memory into static memory and heap memory, but we didn't talk about how the OS manages dynamically the heap using the memory allocation algorithm. There are classic algorithms for memory allocations. Every algorithm has its pros and cons. I would like to introduce the typical first fit algorithm which is used in FreeRTOS. Let's see how the first fit algorithm works. Suppose we have a heap memory space. The OS will maintain a heap memory and allocate and free them dynamically. The memory space has five memory blocks with different sizes. First fit algorithm allocates memory like this. If we want to request 50 kilobytes of memory, it finds the first available memory block that can be a fit. So in the current heap memory space, the first memory block doesn't fit, but the second one does. Then the memory is allocated. After the user finishes using it and frees it, it becomes available again. In another example, if we have a memory space like…

Contents