Replacing C's memcpy with a D implementation
Mike Franklin
slavo5150 at yahoo.com
Mon Jun 11 08:12:35 UTC 2018
On Monday, 11 June 2018 at 08:00:10 UTC, Walter Bright wrote:
> Making it a template is not really necessary. The compiler
> knows if there is the possibility of it throwing based on the
> type, it doesn't need to infer it.
There are other reasons to make it a template, though. For
example, if it were a template, it would not rely on `TypeInfo`
and could then be used in -betterC-like situations. For setting
the length of an array, there are issues with memory allocation
that hinder that, but I'm thinking beyond just setting the length
of an array here; I just used that as an illustrative example.
I think there might also be optimization opportunities using
templates, metaprogramming, and type introspection, that are not
currently possible with the current design.
So there are other reasons to pursue a template design for all of
our runtime hooks, and if our memcpy, memcmp, etc.. are also
templated it't turtles all the way down. We have to be careful
about code bloat with tempates, but I think that can be mitigated.
Mike
More information about the Digitalmars-d
mailing list