Код: Выделить всё
int fd;
std::size_t fs;
fd = open(filename, O_RDONLY); // error management omitted for the example
fs = get_size_from_fd(fd); // legacy function using fstat
void *buff = mmap(NULL,fs,PROT_READ,MAP_SHARED,fd,0);
Далее в коде я нахожу:
Код: Выделить всё
unsigned char *ptr = (unsigned char*)buff; // legacy code, first change would be to make it a reinterpret_cast
// then loops on bytes from ptr.
Код: Выделить всё
unsigned char *get_object_representation(void *buffer, std::size_t N)
{
std::memmove(buffer, buffer, N); // implicitly creates an array of unsigned char
return std::launder(reinterpret_cast(buffer));
}
Код: Выделить всё
unsigned char *ptr = get_object_representation(buff,fs);
// then loops on bytes from ptr
(https://man7.org/linux/man-pages/man2/mmap.2.html говорит только:
В случае успеха mmap() возвращает указатель на отображаемую область
).
Иначе, существует ли правильный способ доступа к байтам, доступным из mmap, четко определенным способом?
Подробнее здесь: https://stackoverflow.com/questions/797 ... ed-by-mmap
Мобильная версия