Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I beat the subject of data representation completely to death in my article "Pointers, References and Values" at:

http://www.warplife.com/tips/code/c++/memory-management/para...

One of the worst performance problems in C++ is quite commonly the creation of invisible temporaries. Sometimes they are necessary but commonly they are not.

There are specific cases where it's better to pass a value rather than a reference, for example if you have an integer in a register, and your parameter passing conventions calls for passing parameters in registers, then passing that integer as a value, rather than a reference (const or otherwise) avoids the use of memory; it also avoids the use of the memory cache, which is likely to be a more serious problem.

In general, for a C++ program to make lots of allocations of just one class isn't such a bad thing. If your default implementation is slower than you like, you might be able to speed things up considerably, as well as save memory, reduce disk paging and so on by using a custom memory allocator just for that class.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: