Anteru's blog
  • Consulting
  • Research
    • Assisted environment probe placement
    • Assisted texture assignment
    • Edge-Friend: Fast and Deterministic Catmull-Clark Subdivision Surfaces
    • Error Metrics for Smart Image Refinement
    • High-Quality Shadows for Streaming Terrain Rendering
    • Hybrid Sample-based Surface Rendering
    • Interactive rendering of Giga-Particle Fluid Simulations
    • Quantitative Analysis of Voxel Raytracing Acceleration Structures
    • Real-time Hybrid Hair Rendering
    • Real-Time Procedural Generation with GPU Work Graphs
    • Scalable rendering for very large meshes
    • Spatiotemporal Variance-Guided Filtering for Motion Blur
    • Subpixel Reconstruction Antialiasing
    • Tiled light trees
    • Towards Practical Meshlet Compression
  • About
  • Archive

C++ tricks, #2: Parameter passing

April 22, 2007
  • Programming
approximately 1 minutes to read

From time to time, I’m taking a look at Aqsis, and recently I started a discussion about passing parameters by const reference instead of value for integral types, under the assumption that it is just as fast (as the compiler notices hey this type fits in a register, don’t bother passing a pointer …). I was quite sure I have seen this with VC7.1. However, Chris Foster wrote a small test case that showed there is indeed a difference, from 1-2% with VC8 (and the generated ASM is different) to 5% (GCC4) to 100% (GCC 3.4) So, passing floats by const reference is no good if you want fast code (except you’re using Intel C++, this one did optimize it). If you are writing generic code, where you don’t know how large your types are, there is a Boost.org provided solution that I totally forgot (thanks Andrew J. Bromage for pointing it out) that selects the optimal type for parameter passing depending on whether the type is smaller than a pointer or not: Call traits, which work great and do their job.

Previous post
Next post

Recent posts

  • Data formats: Why CSV and JSON aren't the best
    Posted on 2024-12-29
  • Replacing cron with systemd-timers
    Posted on 2024-04-21
  • Open Source Maintenance
    Posted on 2024-04-02
  • Angular, Caddy, Gunicorn and Django
    Posted on 2023-10-21
  • Effective meetings
    Posted on 2022-09-12
  • Older posts

Find me on the web

  • GitHub
  • GPU database
  • Projects

Follow me

Anteru NIV_Anteru
Contents © 2005-2025
Anteru
Imprint/Impressum
Privacy policy/Datenschutz
Made with Liara
Last updated February 03, 2019