Urgent.News

What's breaking now, across thousands of outlets.

Tech

Writing Efficient C++ Code

This article, originally published in Polish in Programista magazine in 2013, discusses the importance of writing efficient C++ code. While high-level languages offer many advantages for numerous applications, there are instances where native C++ is necessary to achieve optimal performance.

C++ is a complex language with a steep learning curve, often considered controversial. However, it remains the best or even only choice for many applications, particularly those requiring high performance. Its unique property lies in its balance between high-level features, such as object-oriented programming and custom data structures, and low-level control over hardware.

C++ provides access to the hardware itself, bypassing virtual machines or frameworks. This allows developers to manage memory allocation and deallocation manually, without relying on a garbage collector that operates unpredictably. Furthermore, there are numerous libraries available for C++ and compatible compilers for various platforms.

As software becomes increasingly complex and hardware faster, the need for efficient code persists. Although a faster processor or more RAM may seem cheaper than a skilled programmer's time, performance becomes crucial when a program runs for years or is installed on millions of machines. This is especially true in computing clusters, data centers, and smaller devices like smartphones and tablets, where power and cooling costs, as well as battery life, are significant concerns.

C++ is particularly valuable in applications where code must run at a specified speed without compromise. This includes data processing in real-time, such as games with frame rates affecting the animation smoothness or real-time media stream processing at a specified bitrate. Performance constraints also apply to PCs with fixed processor speeds and RAM, especially for simple casual games.

Object-oriented programming (OOP) offers a remedy for the challenges faced by programmers and teams who find writing large systems in a structured manner too difficult. OOP allows code to consist of classes that group data and methods, serving as abstractions of real-world concepts or problem domains. These classes should be as independent and reusable as possible.

However, OOP can be understood in two ways: conceptually, focusing on the philosophy behind its elements, and technically, as a programming-language mechanism for convenience. It is essential to understand the underlying mechanisms and limitations of OOP to write efficient code. This is where the concept of Data-Oriented Design (DOD) comes into play.

DOD suggests focusing during design and coding on the data that will be stored, its layout in memory, and the design of suitable data structures. Only then should developers consider the algorithms that will operate on this data. This approach seems to return to the idea of structured programming but does not rule out using classes and object-oriented programming benefits. Instead, it encourages thinking closer to hardware and leveraging the language's mechanisms to create simple, efficient code.

Written by urgent.news from Lobsters's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

This story

This is one outlet's version. Read the fullest account.

Read the original at asawicki.info →

More in Tech

DDRop: The $159 Attack That Breaks "Unbreakable" Cloud Encryption

If you've ever trusted "confidential computing" to keep your data safe from a cloud provider itself — even a malicious one — a paper disclosed this month should get your attention.

  • DDRop flaw reveals vulnerability in confidential computing technologies.
  • $159 circuit board interposer drops write commands, bypasses encryption.
  • Attack grants full control over protected VMs, requires server software control.

Building a 3D Exploration Game with Three.js

Back story (For performance optimizations, skip to the next section ;)) The game development club I am a part of had to present themselves in front of the freshers at my college, and being a Technical…

Julia 1: A 144M-Parameter Decision Model Trained for $104

A small AI lab in Brazil just released a model with an unusual claim. Not "beats GPT." Not "agentic superintelligence." The claim is this: a 144.3-million-parameter model that picks the right answer…

  • Julia 1 is a 144.3-million-parameter decision model
  • Trained for $104 on CPU, tablet, or low-end chip
  • Designed to classify answers from a list of options

More from Sunday 27 September →