devxlogo

Returning Large Objects from a Function Efficiently and Safely

Returning Large Objects from a Function Efficiently and Safely

“getter” member functions usually return a result by value. However, when the returned value is a large object, a string for example, returning it by value can be very inefficient. Returning the result by reference rather than by value, as in:

 string & Person::get_name(){ return name;}

solves the overhead problem. Alas, this technique isn

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist