Once there is a way to get additional memory from whatever underlying >environment is there, malloc() and free() can be implemented (and I
believe most often are implemented) without needing to compare
pointers. Note: pointers can be tested for equality without having
to compare them relationally, and testing pointers for equality is >well-defined between any two pointers (which may need to be converted
to 'void *' to avoid a type mismatch).
According to Tim Rentsch <tr.17687@z991.linuxsc.com>:
Once there is a way to get additional memory from whatever underlying >>environment is there, malloc() and free() can be implemented (and I
believe most often are implemented) without needing to compare
pointers. Note: pointers can be tested for equality without having
to compare them relationally, and testing pointers for equality is >>well-defined between any two pointers (which may need to be converted
to 'void *' to avoid a type mismatch).
I suppose it's possible, but the versions I know keep free lists
and consolidate adjacent free chunks which requires comparing the
pointers.
I suppose it's possible, but the versions I know keep free lists
and consolidate adjacent free chunks which requires comparing the
pointers.
Assuming the malloc implementation associates metadata with the
allocation (e.g. in bytes either before the returned pointer or
after the allocation), the comparision for consolidation should
always be standard supported equality comparisons.
According to Scott Lurndal <slp53@pacbell.net>:
I suppose it's possible, but the versions I know keep free lists
and consolidate adjacent free chunks which requires comparing the >>>pointers.
Assuming the malloc implementation associates metadata with the
allocation (e.g. in bytes either before the returned pointer or
after the allocation), the comparision for consolidation should
always be standard supported equality comparisons.
I've seen allocators that sort the free list. And then there's
other approches like buddy allocators that futz directly with
the address bits.
You probably could write a malloc/free that worked without doing
anything other than equality comparisons but I doubt it would be a
very good ones. The real ones I've seen also have tons of defensive
compares to try to check for pointer smashing.
According to Tim Rentsch <tr.17687@z991.linuxsc.com>:
Once there is a way to get additional memory from whatever underlying
environment is there, malloc() and free() can be implemented (and I
believe most often are implemented) without needing to compare
pointers. Note: pointers can be tested for equality without having
to compare them relationally, and testing pointers for equality is
well-defined between any two pointers (which may need to be converted
to 'void *' to avoid a type mismatch).
I suppose it's possible, but the versions I know keep free lists
and consolidate adjacent free chunks which requires comparing the
pointers.
Sysop: | DaiTengu |
---|---|
Location: | Appleton, WI |
Users: | 994 |
Nodes: | 10 (0 / 10) |
Uptime: | 97:10:50 |
Calls: | 13,016 |
Calls today: | 2 |
Files: | 186,574 |
Messages: | 3,282,095 |