3 ms·
Do you mind spelling out the few lines of code needed to do this?
by sigjuice 10y ago
Do you mind spelling out the few lines of code needed to do this?
- slrz 10y agoSomething like the following: void* pedanticmemmove(void *dst, const void *src, size_t n) { char buf[n > THRESHOLD ? 1 : n]; char *p = n > THRESHOLD ? xmalloc(n) : buf; memcpy(p, src, n); memcpy(dst, p, n); if (n > THRESHOLD) free(p); return dst; } But yeah, the alloca(3) variant is a bit nicer to look at and probably results in exactly the same code (but is non-standard, of course).