News for hackers. Stuff that matters.
Re:The Horror in the Standard Library by naasking on Saturday May 06, 2017 @01:27AM (#14278839)
They only store the size in a header because free() needs to know the size on deallocation. Think about all the C string functions that take buffer length parameters and what an outcry there would be if we eliminated all the size parameters and placed string lengths as headers before the buffer itself.

It's terrible for performance because you're giving up control, even if it is a little safer overall.

Re:The Horror in the Standard Library by asveikau on Saturday May 06, 2017 @04:21AM (#14279292)
That'd be silly. Among many other problems, it would mean you can't do things like take a substring of a const buffer via pointer arithmetic, because you'd need to add a header in the middle.

It's better to pick exactly one of: (1) embrace the true nature of allocations and figure out lengths yourself or (2) if you are less comfortable with that, use some other language which doesn't expose any of this.

Re:The Horror in the Standard Library by naasking on Saturday May 06, 2017 @09:47AM (#14280208)
> That'd be silly. Among many other problems, it would mean you can't do things like take a substring of a const buffer via pointer arithmetic, because you'd need to add a header in the middle

Right, and now you understand​ why free should have always accepted a size parameter, just like malloc.

Re:The Horror in the Standard Library by asveikau on Saturday May 06, 2017 @10:47AM (#14280460)
No, I don't. Doing zero-copy substrings of a read only buffer and an allocator chopping up a writable buffer into multiple chunks are very different scenarios.
Re:The Horror in the Standard Library by naasking on Saturday May 06, 2017 @11:41PM (#14283724)
Not for this purpose. It's all about knowing where the boundaries are.