On 7/30/12 4:34 AM, Dmitry Olshansky wrote:
On 30-Jul-12 06:01, Andrei Alexandrescu wrote:
In fact memcpy could and should be replaced with word by word copy for
almost all of struct sizes up to ~32 bytes (as size is known in advance
for this particular function pointer i.e. handler!int).

In fact memcpy should be smart enough to do all that, but apparently it
doesn't.


I'd say array ops could and should do this (since compiler has all the
info at compile-time). On the other hand memcpy is just one tired C
function aimed at fast blitting of any memory chunks.
(Even just call/ret pair is too much of overhead in case of int).

memcpy is implemented as an intrinsic on many platforms. I'm not sure whether it is on dmd, but it is on dmc (http://www.digitalmars.com/ctg/sc.html), icc, and gcc (http://software.intel.com/en-us/articles/memcpy-performance/). But then clearly using simple word assignments wherever possible makes for a more robust performance profile.

I'm thinking more of it and common types are just uint, int, long,
ulong, double, string. In fact most of e.g. int x string and such are
"throw me an exception" entries, they could be merged.
Then we could make 2-stage table to save some space, it sounds like
trie, hm....

You can implement it via visitation too (two indirect calls, no search). "Modern C++ Design" discusses possible approaches at length.


Andrei


Reply via email to