Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8640033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:10:40+00:00 2026-06-12T11:10:40+00:00

In a previous program that I have written in C I needed a single

  • 0

In a previous program that I have written in C I needed a single object with several “core” data in it that can be accessed by all the functions in my program, I end up picking a struct and i have used a pointer to this struct for reading or writing data; it was fast and good for the job, also it was cheap because accessing a pointer is probably one of the cheapest thing that you can do in C and I have never found something better so I’m happy with this solution.

Now in C++ I have the same problem, I need to share a state composed of some primitive types, I’m tempted to use one of the so called POD, which basically mean, struct, again, but this time with references for safety.

Supposing that I need this “Blob” of data to be carried around my program, a struct accessed by reference is the fastest thing in C++? How much a getter methods can cost?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T11:10:41+00:00Added an answer on June 12, 2026 at 11:10 am

    If your getter code is inline (in the header file), then the compiler can eliminate the need to call a function in the machine code it outputs.

    eg:

    class Data
    {
    private:
      int number_;
    public:
      int GetNumber() { return number_; }
    };
    

    The compiler will see GetNumber’s definition, will know what it does is simple and and where you’ve called GetNumber(), it will simply replace it with number_. So, using a getter versus accessing the member directly will result in the equivalent code, and both will perform the same.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a (C#) genetic program that uses financial time-series data and it's currently
I have a data object used to contain my UI data that supports INotifyPropertyChanged
This is a test program that I have written for a larger project that
I have written a small program to validate 3 data files and convert them
I am writing a program to communicate over the serial port. All data that
I have many objects reference the same class of stored data. In previous programs,
I have to write a program that will essentially sort nodes in a linked
So i am trying to compile my LinkedList for a program that i have
I have to create a C# program that deals well with reading in huge
I am have a powershell script that does a few things that all need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.