Exemplo n.º 1
0
/*
 * delete_freenode - delete the block from free list when it is allocated
 */
static void delete_freenode(void *bp)
{
    void *next_free_block_addr = (void *)*NEXTP(bp);
    void *prev_free_block_addr = (void *)*PREVP(bp);
    PUT_ADDR(NEXTP(prev_free_block_addr), next_free_block_addr);
    if (next_free_block_addr != NULL) {
        PUT_ADDR(PREVP(next_free_block_addr), prev_free_block_addr);
    }
    
}
Exemplo n.º 2
0
/*
 * insert_freenode - insert the freed block to the free list
 */
static void insert_freenode(void *bp)
{
    size_t size = GET_SIZE(HDRP(bp));
    void *root = getroot(getclass(size));
    void *next_free_block_addr = (void *)*NEXTP(root);
    PUT_ADDR(NEXTP(bp), *NEXTP(root));
    PUT_ADDR(PREVP(bp), root);
    
    PUT_ADDR(NEXTP(root), bp);
    if (next_free_block_addr != NULL) {
        PUT_ADDR(PREVP(next_free_block_addr), bp);
    }
}
Exemplo n.º 3
0
/*
 * insert_freenode - insert the freed block to the free list
 */
inline void insert_freenode(void *bp)
{
    size_t size = GET_SIZE(HDRP(bp));
    void *root = getroot(getclass(size));
    void *nextp = next_free_blck(root);
    void *prevp = root;
    for (; nextp!=NULL && GET_SIZE(HDRP(nextp)) < size; prevp = nextp, nextp = (char *)next_free_blck(nextp)) {

    }

    PUT_ADDR(NEXTP(bp), nextp);
    PUT_ADDR(PREVP(bp), prevp);
    PUT_ADDR(NEXTP(prevp), bp);
    if (nextp != NULL) {
        PUT_ADDR(PREVP(nextp), bp);
    }
}
Exemplo n.º 4
0
Arquivo: mm.c Projeto: horf31/ece454
/**********************************************************
 * insert_freelist
 * Place the free block ptr bp on the appropriated
 * segregated free list
 * Insert at the first element of the list
 **********************************************************/
void insert_freelist(intptr_t * bp) {
	// Find out which list should the free block insert to
	int index = size_to_index(GET_SIZE(HDRP(bp)));

	// Head of the list
	intptr_t * listp = seg_free_list[index];

	// Set the prev_ptr and next_ptr of the current block
	PUT(bp, GET(seg_free_list[index]));	// next
	PUTP(PREVP(bp), listp);             // prev

	// If the list previously has elements inside
	if (GET(listp) != 0) {
		// Set the next element to point to the current bp
		PUTP(PREVP(*listp), bp);
	}
	//Set head to point to the current bp
	PUTP(listp, bp);
}
Exemplo n.º 5
0
Arquivo: mm.c Projeto: horf31/ece454
/**********************************************************
 * delete_from_list
 * Place the free block ptr bp on the appropriated
 * segregated free list
 * Insert at the first element of the list
 **********************************************************/
void delete_from_list(void *bp) {
	// If the block is allocated, cannot be freed
	if (GET_ALLOC(HDRP(bp))) {
		return;
	}

	// If it does not have next element
	if (*(char*) bp == 0) {
		// Set previous block ptr in the previous element to 0
		PUT(PREVB(bp), 0);
	} else { // If it has next element
		// Set next block ptr in the prev element to current's next element
		PUTP(PREVB(bp), NEXTB(bp));
		// Set prev block ptr in the next element to current's prev element
		PUTP(PREVP(NEXTB(bp)), PREVB(bp));
	}
}