We are forking D
Walter Bright
newshound2 at digitalmars.com
Mon Jan 8 23:32:25 UTC 2024
On 1/7/2024 6:58 PM, Don Allen wrote:
> The speed of the code generated by the language you are using is not necessarily
> the determining factor of the speed of your application.
Interestingly, C string processing is pretty slow, in spite of it being a "too
the metal" language.
The reason is simple. C strings are 0-terminated. This means that whenever you
want to refer to a slice of a string that does not include the end, it is
necessary to allocate memory, copy the slice to it, add a terminating 0, and
then some time later free the memory.
This is quite wasteful and inefficient.
Another egregious source of inefficiency in C is the never-ending re-scanning of
strings to find the length of them. This is CPU-intensive, and very
cache-unfriendly.
This is where D's slices shine.
Yes, you can emulate D slices in C, but essentially every C API uses 0
terminated strings so you're borked anyway.
More information about the Digitalmars-d
mailing list