3 ms·
Isn't that the definition of an array? Chunk of contiguous memory plus a notion of how to subdivide it into equal parts?
by corndoge 9y ago
Isn't that the definition of an array? Chunk of contiguous memory plus a notion of how to subdivide it into equal parts?
- kuschku 9y agoYes, exactly. A chunk of memory. A chunk has an end. But "arrays" in C aren't a chunk of memory, just the info where it starts and how large elements are.
- hedora 9y agoThe problem is that a frightening number of people don't bother to write the half-dozen obvious wrappers around this, and stdlib doesn't provide them either: struct buf { uint8_t * base, size_t size };
- kbenson 9y ago> The problem is that a frightening number of people don't bother to write the half-dozen obvious wrappers around this That's likely because having to pass it in and out of functions and libs that don't expect your special structure might cause it to have an invalid length, and then all your special wrappers can become a liability and not an advantage through either assuming your bufs are valid, or defensively checking more than is necessarily because they can't know whether it was altered or not. > stdlib doesn't provide them either Which is the real problem. That would make them a de facto standard, and a lot (but probably not all) of the problems would be mitigated by people accepting the performance trade offs needed to make them safe.
- kbart 9y agoThat doesn't solve the problem because you still have to set 'size' manually.
- Tanegashima 9y agoNo, that’s the implementation of an array. In reality an array is an array.