My machine is ubuntu 20.04
I have a assignment that say "Using the system calls (mmap and munmap) implement your own functions for dynamic memory allocation: mymalloc and myfree, which have the same functionality as malloc and free from the standard C library. Save the implementations in files mymalloc.h and mymalloc.c."
And then it says "we must allocate at least the desired length + the size of the variable for storing the length (size_t). We store the length as first element, then return the next element."
It is my code (size is parameter in type size_t)
size_t total_size = size + sizeof(size_t);
size_t allocation_overflow = total_size % page_size;
if(allocation_overflow > 0)
total_size += page_size - allocation_overflow;
void *data = mmap(NULL ,total_size, PROT_EXEC | PROT_READ | PROT_WRITE , MAP_PRIVATE , 0 , 0);
// size_ptr will point to stored size
size_t *size_ptr =(size_t *)data;
size_ptr[0] = total_size;
// pointer to allocated memory
void* allocated_mem_pointer = data + sizeof(size_t);
and it give warning "pointer type 'void*' used in arithmetic [-Wpointer arith]"
ı must store the length in first element because assignment says it but ı don't warnings ı want to write clean code . İS there a legal for it. I already read Pointer arithmetic when void has unknown size but couldnt find any answer to solve it.