I need to keep track of a lot of boolean-esque data in C. I'm writing a toy kernel and need to store data on whether a certain memory address is used or free. Because of this, I need to store and traverse through this data in the fastest, most efficient way possible. Since I am writing the kernel from scratch I cannot use the C Standard Library. What's the best, fastest, most efficient way to organize, traverse through and modify a large series of boolean-esque data without using the C Standard Library? E.g. would a bitmap or an array or linked list take the least amount of resources to traverse and modify?
Asked
Active
Viewed 173 times
1
-
1I'm not sure what you're asking, but a bit vector or a bit set / bit array may be what you need? – Morten Jensen Nov 11 '15 at 00:09
-
I'll make a quick clarification in the question. – Michael Morrow Nov 11 '15 at 00:09
-
So bit manipulation would be the fastest, least resource consuming technique? – Michael Morrow Nov 11 '15 at 00:11
-
It depends on how you want to identify each boolean. If they have consecutive indexes then a simple bit array is easiest and fastest – interjay Nov 11 '15 at 00:13
-
Well, there's all the other things.. Do you need to track ownership? Can you store memory-management data in the free areas? – Martin James Nov 11 '15 at 00:19
-
This is just for physical page frames. I intend on using page tables and page directory to keep track of ownership. And to answer your last question, yes. – Michael Morrow Nov 11 '15 at 00:20
-
You might want to look at this question: http://stackoverflow.com/questions/4372515/how-to-implement-a-bitset-in-c – bruceg Nov 11 '15 at 02:22
1 Answers
1
Many filesystems have the same problem: indicating whether an allocation unit (group of disk sectors) are available or not. Except for MSDOS's FAT, I think all use a bitmap. Definitely NTFS and Linux's ext/ext2/ext3/ext4 use bitmaps.
There are several easy optimizations to make. If more than 8/16/32/64 sequential units are needed for an allocation, checking that many bits at once is simple using the corresponding integer size. If a bit being zero means "available", then testing for a zero integer tells whether the whole allocation is available. However, boundary optimizations might need to be considered.

wallyk
- 56,922
- 16
- 83
- 148