3 ms·
Is a 5 billion character string really the way you want to read a 5GB file?
by dpark 8y ago
Is a 5 billion character string really the way you want to read a 5GB file?
- beagle3 8y agoNo, but some people do; And some C programs written 30 years ago do support it, but no Pascal program does (not from 30 years ago, not those written 20 years ago, not those written 10 years ago, and not those written yesterday unless Pascal now has 64-bit length strings). Furthermore, using mmap (which was always the right way to do it), it doesn't matter if it's 512KB or 1GB or 5GB or 20GB, and is supported by C string practices but none of the Pascal strings (or those suggested on this thread).
- dpark 8y agoOn the other hand, the Pascal code that can't handle 5GB strings also doesn't have the same pervasive security risk from buggy string manipulation that C code does. Not a bad tradeoff, especially given that you probably want to work on substrings within that 5GB and slicing in C essentially doesn't work because null termination either doesn't exist for your substrings (making them incorrect and potentially unsafe, depending on what you're doing) or the substring null termination breaks your larger string and prevents it from actually behaving like a 5GB string. Safe string manipulation in C devolves into always passing a char array and a count anyway, which is not coincidentally exactly what Pascal strings look like.
- beagle3 8y agoIndeed safe strings in C are hard to do, but the nul termination is not the end-all-be-all of C strings; indeed, there is often a way to specify maximum string length (e.g. %.#s format in the prints family, strncpy). So mmapped strings are actually useful. The bigger problems is embedded nuls, which can’t easily be sidestepped in the C strong framework. Regardless, C won when the world was not yet well connected, and vulnerabilities mattered much less. It might not have won if the match was held today. The wake up calls were the Morris worm (intentional) and the AT&T outage (unintentional, and more of a logic error iirc) but by then it was too late.