Allocating Paragraphs
Posted: Sat Apr 25, 2009 2:36 pm
This isn't exactly OS development specific, but if the mods feel it's better put elsewhere it won't hurt my feelings (unless, of course, it's the trash...).
In case you didn't know, I've decided to make my first O.S. a DOS++. Basically it's a simple DOS with a few extra features. I'm getting to the point where I might want to have my int 21h AH=48h, AH=49h and AH=4Ah (allocate a block, free a block, and resize a block) working to make my life a bit easier. Obviously with a block being a multiple of 16 bytes using segments is the way to go for accessing them, but what I'm having trouble with is figuring out the best way to mark these blocks as allocated/freed. A bitmap seems a bit wasteful, but so does using 16 bytes immediately before the block to store allocation structures (assuming allocations have to be on a 16-byte boundary).
I can see 2 options:
1) A bitmap which would be best for lots of small allocations
2) A linked-list type structure before the allocated block which would be best for a few big allocations
Using a bitmap, assuming I fill memory with a bunch of single-paragraph allocations, would use a constant 5KB of RAM, whereas with the linked-list approach it would waste about 50% of RAM. (5KB == 640KB / 16 Bytes per paragraph / 8 bits per byte in bitmap)
Assuming I fill memory with a single all-of-RAM allocation a bitmap would waste most of the 5KB but the linked-list would use only 16 bytes.
My question is which should I use, and are there any other options that I might want to consider but am missing?
In case you didn't know, I've decided to make my first O.S. a DOS++. Basically it's a simple DOS with a few extra features. I'm getting to the point where I might want to have my int 21h AH=48h, AH=49h and AH=4Ah (allocate a block, free a block, and resize a block) working to make my life a bit easier. Obviously with a block being a multiple of 16 bytes using segments is the way to go for accessing them, but what I'm having trouble with is figuring out the best way to mark these blocks as allocated/freed. A bitmap seems a bit wasteful, but so does using 16 bytes immediately before the block to store allocation structures (assuming allocations have to be on a 16-byte boundary).
I can see 2 options:
1) A bitmap which would be best for lots of small allocations
2) A linked-list type structure before the allocated block which would be best for a few big allocations
Using a bitmap, assuming I fill memory with a bunch of single-paragraph allocations, would use a constant 5KB of RAM, whereas with the linked-list approach it would waste about 50% of RAM. (5KB == 640KB / 16 Bytes per paragraph / 8 bits per byte in bitmap)
Assuming I fill memory with a single all-of-RAM allocation a bitmap would waste most of the 5KB but the linked-list would use only 16 bytes.
My question is which should I use, and are there any other options that I might want to consider but am missing?