I have this assignment to write my own malloc program and I am having some trouble. I am using a doubly linked list to manage free space and used space, and using next fit to allocate the memory. the problem that i am writing about is when i return the pointer to the program, it returns the wrong value here is the relevant code for this problem i think
if(found==0){
printf("INLOOP5 update\n");
newnode=(struct memory *)sbrk(sizemal+sizeof(struct memory));
printf("NEWNODE %X: \n", newnode);
newnode->next=NULL;
newnode->previous=tail;
tail=newnode;
tail->size=sizemal;
lastseen=head;
printf("NEW NODE %X: \n", newnode);
printf("TAIL: %X\n", tail);
}
}
void *returnsize=lastseen+sizeof(struct memory);
printf("LAST SEEN: %X SIZEOFDLL: %X RETURNVAL: %X\n", lastseen, sizeof(struct memory), returnsize);
printf("TAIL %X LASTSEEN %X\n", tail, lastseen);
printf("RETURN: %x: \n", lastseen+sizeof(struct memory));
return (lastseen+sizeof(struct memory));
}
ALL VALUES BELOW ARE IN HEX
the number returned should be 502048 but it is returning 502240
502030 is the start of the tail and the size of the structure is 18
so the structure starts at 502030 and ends at 502047 so 502048 should be returned.... Any ideas as how to fix this problem?