Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C++ Template Question

Name: Anonymous 2012-10-07 21:47


template <size_t N>
void print_members(int (&arr)[N]) { ... }


so is C++ going to create a new function for every different sized array I use

Name: Cudder !MhMRSATORI!fR8duoqGZdD/iE5 2012-10-09 1:39

>>16
Having compact data in the cache is better than "loose" code in there, especially if that long line of code is big enough to make a loop fall out of the cache. A plain call+push imm8 is 7 bytes; even if you stored that array as 4-byte ints (thus wasting 3/4 of the space in that example) you're still getting an improvement: 7n vs 4n + loop code overhead. Store as single bytes and you get even better density, it's now 7n vs 1n + overhead.

"instructions" and "data" are the same to the memory, don't think instruction fetches are free.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List