News for hackers. Stuff that matters.
Re:Checked C by KingLancelot on Wednesday December 21, 2022 @02:49PM (#34085501)
Fat pointers are a good idea, but I think it’d be a better idea to store the start and evd pointers instead of a pointer to the first element and a size_t.
Re:Checked C by 1980phipsi on Wednesday December 21, 2022 @03:24PM (#34085927)
Why?
Re:Checked C by masklinn on Wednesday December 21, 2022 @03:46PM (#34086179)
I'd guess it's because that's what C++ does. Though it's unclear to me that C++-style iteration (where you increment a running pointer until you reach an EOI pointer) is much used in C.
Re:Checked C by WalterBright on Wednesday December 21, 2022 @04:00PM (#34086327)
Storing two pointers into the same array is a memory safety problem. It's hard to implement a borrow checker when there are two live mutable pointers into the same memory object.
Re:Checked C by int_19h on Friday December 23, 2022 @06:15PM (#34111750)
I would expect the borrow checker to treat a slice as a logical pointer to all elements that are addressable through it, regardless of how it's implemented under the hood.
Re:Checked C by int_19h on Friday December 23, 2022 @06:14PM (#34111741)
This pattern originated in C; C++ iterators were specifically designed to fit it when it was already established.
Re:Checked C by andrewmcwatters on Wednesday December 21, 2022 @11:28PM (#34089793)
I've never heard of a good argument for this as compared to a capacity, length, and data struct.

If you have a start and end pointer and you move either one, you don't know what the original size of the allocation was.

Re:Checked C by ntrel on Friday December 23, 2022 @06:09AM (#34104520)
D doesn't store capacity in each slice. This allows a slice to fit in registers more often. Instead for GC allocated slices, the GC will store metadata before the first element of the allocation. That does make it slower to access, particularly when the slice points past the first element, but it is cached to speed up repeated accesses to the same allocation. Repeated appending can be further speeded up by using a dedicated Appender type.