I am writing software to simulate a “first fit” memory allocation scheme.
Basically, I allocate a large X megabyte chunk of memory and subdivide it into blocks when chunks are requested in accordance with the scheme.
I use a linked list called "node" as a header for each memory block (so that we can find the next block without a tedious loop through each address value.
head_ptr = (char*) malloc(total_size + sizeof(node));
if(head_ptr == NULL) return -1;
node* head_node = new node;
head_node->next = NULL;
head_node->previous = NULL;
memset(head_ptr,head_node, sizeof(node));
`
But this last line returns:
error: invalid conversion from 'node*' to 'int'
I understand why this is not true. But how can I put my node at the pointer location of my newly allocated memory?
source
share