I am reading about c++ allocators and the deallocate function has sentence that got my attention:
The argument n must be equal to the first argument of the call to allocate() that originally produced p; otherwise, the behavior is undefined.
Why is that? Why couldn't one deallocate part of the allocated memory, stupid example:
#include <memory>
#include <string>
int main()
{
std::allocator<std::string> alloc;
auto const p = alloc.allocate(20);
alloc.deallocate(p+10, 10);
return 0;
}