Buddy Allocation
Posted: Thu Jan 21, 2010 12:05 pm
Hello,
Working on my own OS (written in C++), I've come to a point to write a memory manager, and I've decided to go for buddy allocation. I only have one issue with this principle; imagine the following situation:
(# = used block; . = free block; xxK = block size)
Let's say we want to free 20K (=5 blocks of 4K) starting on with the second block; we now have this situation:
Now one would say a block of 16K has been made available, while actually, there isn't (because there is no sequence of 4 free blocks on a 16K boundary)!
I could move other 4K blocks (or larger pieces of memory) around; but in my opinion this would cause problems, for example:
where 'alloc' returns the starting address of the allocated memory. If I move used chunks of memory around, then 'obj' won't be pointing to the actual object anymore!
Am I missing something or is this a negative side-effect of buddy allocation?
jensvdb
Working on my own OS (written in C++), I've come to a point to write a memory manager, and I've decided to go for buddy allocation. I only have one issue with this principle; imagine the following situation:
(# = used block; . = free block; xxK = block size)
Code: Select all
4K ########
8K # # # #
16K # #
32K #
Code: Select all
4K #.....##
8K # # # #
16K # #
32K #
I could move other 4K blocks (or larger pieces of memory) around; but in my opinion this would cause problems, for example:
Code: Select all
Object *obj = (Object *)alloc(sizeof(Object));
Am I missing something or is this a negative side-effect of buddy allocation?
jensvdb