// half_fit.c
// Half-Fit
//
#include
#include
#include "half_fit.h"
#include "type.h"
#include "math.h"
//unsigned char array[MAX_SIZE] __attribute__ ((section(".ARM.__at_0x10000000"), zero_init));
#define MEMORY 32768
#define BASE_ADDR (void*) 0x10000000 static header_free* buckets[11];
/* START Helper Functions
*/
// CEIL_32 Function
U32 CEIL_32 (U32 value) { // Re-adjust value to round up (or ceil) to nearest multiple of 32 return ((value-1)/32 + 1) * 32; // (e.g. 32->31->0->1->32, 196->195->6->7->224) // ^OPTIMIZE OPTION: USE BITWISE OPERATORS
}
// Function to calculate required size
U32 adjust_size(U32 initial_size) { // Add 4 bytes because of header size U32 newSize = initial_size + 4; // Re-adjust …show more content…
0 : size/32;
}
// INSERT FUNCTIONS void insert_block(header_free* block) { header* alloc_block = (header*) block; int index = get_bucket_index(get_size(alloc_block)) - 1; // If block isn't the last one in the blocket if(get_next_free(block) != block) { // If block isn't the first one in the bucket either if(get_prev_free(block) != block) { // Connect neighbouring free blocks set_prev_free(get_next_free(block), get_prev_free(block)); set_next_free(get_prev_free(block), get_next_free(block)); } else { // Set the next block as the first one buckets[index] = get_next_free(block); set_prev_free(get_next_free(block), get_next_free(block)); } } else { if(get_prev_free(block) != block) { set_next_free(get_prev_free(block), get_prev_free(block)); } else { buckets[index] = NULL; } } // Separate block from others set_prev_free(block, block); set_next_free(block, block);
}
void insert_free_block(header_free* block)