I allocated a chunk of memory of type char, and the size is 10 MB (i.e. mem_size = 10):
int mem_size = 10;
char *start_ptr;
if((start_ptr= malloc(mem_size*1024*1024*sizeof(char)))==NULL) {return -1;}
Now I want to save the size information in the header of the memory block. To make myself clearer, let's say: start_ptr = 0xaf868004 (This is the value I received from my execution, it changes every time).
Now I want to put size information at the beginning of this pointer, i.e. *start_ptr = mem_size*1024*1024;.
But I can not put this information in start_ptr. I think the reason is that my ptr has a type charthat accepts only one byte, but I'm trying to save int, which takes 4 bytes, is a problem.
I am not sure how to solve this problem.
source
share