koky Posted October 13, 2012 Share Posted October 13, 2012 (edited) Lets say I have a Variable Partitioning with free space: at address 32k a free space of 8k, and at address 15k a free space of size 11k. I need to create a first fit free table. and a best fit free table Am I doing the right thing for both of the tables please help +--------+-------+ |address | size | |32 |8 | |15 |11 | +--------+-------+ Edited October 13, 2012 by koky Link to comment Share on other sites More sharing options...
khaled Posted October 31, 2012 Share Posted October 31, 2012 (edited) **deleted** Edited October 31, 2012 by khaled Link to comment Share on other sites More sharing options...
Ben Banana Posted November 8, 2012 Share Posted November 8, 2012 (edited) Your issue is unclear... In C, I figure that a first-fit block allocation algorithm can be done like this: void* block = 0; unsigned int fitBlock = 0; for ( ; fitBlock != blockQuantity; ++fitBlock) { if (blockFree[fitBlock] && blockSize[fitBlock] >= minimumSize) break; } if (fitBlock == blockQuantity) { // Couldn't make allocation as expected. Handle situation with alternatives ... (e.g. pagefile management). } else { block = blockAddress[fitBlock]; blockFree[fitBlock] = 0; // Block allocated. } Best fit: (a rudimentary implementation) void* block = 0; unsigned int bestFitIndex = 0; unsigned int bestFitSize = sizeOfLargestBlock; unsigned int fitBlock = 0; for ( ; fitBlock != blockQuantity; ++fitBlock) { if (blockFree[fitBlock] && blockSize[fitBlock] >= minimumSize && blockSize[fitBlock] <= bestFitSize) { block = blockAddress[fitBlock]; bestFitSize = blockSize[fitBlock]; bestFitIndex = fitBlock; } } if (blockFree[bestFitIndex] && bestFitSize >= minimumSize) { blockFree[bestFitIndex] = 0; // Block allocated. } else { // Couldn't make allocation as expected. Handle situation with alternatives ... (e.g. pagefile management). } Edited November 8, 2012 by Ben Bowen Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now