memcpy, memset, memcmp and friends in the D Runtime
Dmitry Olshansky
dmitry.olsh at gmail.com
Thu Apr 10 01:41:09 PDT 2014
09-Apr-2014 16:56, Daniel Murphy пишет:
> "monarch_dodra" wrote in message
> news:pdzhmmnjxclrjtkgupoz at forum.dlang.org...
>
>> I think arguably, there should be D equivalents of the C runtime
>> functions, if only for the added safety of slices (for example, memchr
>> could be 100% certifiably safe), and to avoid the rampant
>> deduplication of things as in the above, because of CTFE.
>
> The utility of a 'slightly safer' layer between the C functions and the
> phobos range-based functions is questionable IMO. eg in cases where
> memcpy on arrays is safe, phobos' copy would likely optimize to the
> exact same code.
Pros:
1. No extra scuffolding for CTFE.
2. Type-safe
3. Optional (non-release, etc.) bounds-checking.
4. Less error prone interface, e.g. memset is a known source of bugs in
C, even for tried and true code bases.
5. More flexible, see e.g. memchr as an example.
Cons:
A set of primitives to learn.
--
Dmitry Olshansky
More information about the Digitalmars-d
mailing list