How to make your C++ code faster with an extended stack

  • The allocation cannot persist beyond its function’s scope.
  • The allocation must be small enough in size that it fits into the program’s stack. If we’re unsure, we run the risk of crashing our program with a stack overflow.
  • It knows nothing about C++ constructors of destructors; so if we’re going to use it for non-trivial classes, we need to invoke those manually.
  • alloca can only allocate memory for the function that calls it, which makes it difficult to compose higher-level blocks of functionality.
-----------------------------------------------
Benchmark Time
-----------------------------------------------
BM_compute_median_salary_heap 82201 ns
BM_compute_median_salary_stackext 55363 ns

Conclusion

--

--

--

Mathematical Engineer | buildingblock.ai

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ryan Burn

Ryan Burn

Mathematical Engineer | buildingblock.ai

More from Medium

C Libraries and Their Types

Integrating Lua with C: Part 6

Linux: Software libraries in C

C++ fluent builder pattern