I'm working on a malloc implementation as a school exercise, using mmap.
I would like to compute the size of my block of memory, in my free list, by using the address of the metadata.
But I am not sure this solution would be well-defined inside the C standard, I didn't find a reference on whether or not the mmap allocated region is considered an "object" in the meaning of that part of the C standard :
§6.5.8.5 (quote taken from that answer to a somewhat related question) :
When two pointers are compared, the result depends on the relative locations in the address space of the objects pointed to. If two pointers to object or incomplete types both point to the same object, or both point one past the last element of the same array object, they compare equal. If the objects pointed to are members of the same aggregate object, pointers to structure members declared later compare greater than pointers to members declared earlier in the structure, and pointers to array elements with larger subscript values compare greater than pointers to elements of the same array with lower subscript values. All pointers to members of the same union object compare equal. If the expression
P
points to an element of an array object and the expressionQ
points to the last element of the same array object, the pointer expressionQ+1
compares greater thanP
. In all other cases, the behavior is undefined.
In other words, can I consider the mmap region as a array of bytes (or char
) within the standard ?