Date: Tue, 28 Jan 2025 13:36:49 +0100
Who or what would update the pointers, when relocating?
If the memory of the object is unaligned than the alignment of the pointer storage itself would be violated (in addition to the pointer pointing to memory not aligned to the pointed to type). So a standard relocating function implemented by the class would not work.
A simple memcpy would not be enough to update pointers.
The class would have to know that it could be stored in unaligned memory to do the correct update of the pointer when relocating.
So the class could just store a pointer to std::byte instead.
-----Ursprüngliche Nachricht-----
Von:Frederick Virchanza Gotham via Std-Proposals <std-proposals_at_[hidden]>
Gesendet:Di 28.01.2025 13:13
Betreff:Re: [std-proposals] Make all data pointers intercompatible
An:std-proposals_at_[hidden];
CC:Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>;
On Tue, Jan 28, 2025 at 11:49 AM Jens Maurer wrote:
>
> I still don't understand what exactly you mean by "intercompatible".
Here's what I want:
Point 1) void* and char* are exactly the same.
Point 2) All data pointers have the same size and alignment. So if you
apply "sizeof" or "alignof" to any data pointer, you always get the
same answer. Same representation too, obviously.
Point 3) No loss of precision when converting between pointer types
whose pointed-to type have differing alignment requirements.
Specifically:
Even though the memory address of a 'double' will always be a multiple
of 8, I want the lower 3 bits of the pointer to still retain their
value, so that the following is possible:
Line 1: char c;
Line 2: double *p = static_cast<double*>(static_cast<void*>(&c));
Line 3: char *p2 = static_cast<char*>(static_cast<void*>( p ));
Line 4: *p2 = 'h';
Looking at Line #2, I could see that a compiler could possibly
zero-out the lower 3 bits of the value of 'p', but I want this to be
forbidden in C++26.
This would be a major simplification of data pointers in C++, and it
would aid in relocating objects into unaligned memory (for example
std::basic_string<char32_t> which contains a pointer pointing into its
own internal buffer).
--
Std-Proposals mailing list
Std-Proposals_at_[hidden]
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
Received on 2025-01-28 12:40:24