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

  • SEARCH
  • Home
  • 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 6231031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:51:36+00:00 2026-05-24T09:51:36+00:00

So the problem I am having has not actually happened yet. I am planning

  • 0

So the problem I am having has not actually happened yet. I am planning out some code for a game I am currently working on and I know that I am going to be needing to conserve memory usage as much as possible from step one.

My question is, if I have for example, 500k objects that will need to constantly be constructed and deconstructed. Would is save me any memory to have the functions those classes are going to use as function pointers.

e.g. without function pointers
class MyClass
{
public:
void Update();
void Draw();
...
}

e.g. with function pointers

class MyClass
{
public:
void * Update;
void * Draw;
...
}

Would this save me any memory or would any new creation of MyClass just access the same functions that were defined for the rest of them? If it does save me any memory would it be enough to be worthwhile?

  • 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-05-24T09:51:36+00:00Added an answer on May 24, 2026 at 9:51 am

    Assuming those are not virtual functions, you’d use more memory with function pointers.

    The first example

    There is no allocation (beyond the base amount required to make new return unique pointers, or your additional implementation that you ... ellipsized).

    Non-virtual member functions are basically static functions taking a this pointer.

    The advantage is that your objects are really simple, and you’ll have only one place to look to find the corresponding code.

    The disadvantage is that you lose some flexibility, and have to cram all your code into single update/draw functions. This will be hard to manage for anything but a tiny game.

    The second example

    You allocate 2x pointers per object instance. Pointers are usually 4x to 8x bytes each (depending on your target platform and your compiler).

    The advantage you gain a lot of flexibility of being able to change the function you’re pointing to at runtime, and can have a multitude of functions that implement it – thus supporting (but not guaranteeing) better code organization.

    The disadvantage is that it will be harder to tell which function each instance will point to when you’re debugging your application, or when you’re simply reading through the code.

    Other options

    Using function pointers this specific way (instance data members) usually makes more sense in plain C, and less sense in C++.

    If you want those functions to be bound at runtime, you may want to make them virtual instead. The cost is compiler/implementation dependent, but I believe it is (usually) going to be one v-table pointer per object instance.

    Plus you can take full advantage of virtual function syntax to make your functions based on type, rather than whatever you bound them to. It will be easier to debug than the function pointer option, since you can simply look at the derived type to figure out what function a particular instance points to.

    You also won’t have to initialize those function pointers – the C++ type system would do the equivalent initialization automatically (by building the v-table, and initializing each instance’s v-table pointer).

    See: http://www.parashift.com/c++-faq-lite/virtual-functions.html

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

Sidebar

Related Questions

I'm having some trouble with the django generic object_list function's pagination not really being
I'm working on building Cppcheck on AIX with the xlC compiler (see previous question
I am trying to convert a regular expression into NFA and I am having
I've had a look around to see if this has been answered, and there
With Python2.6, the Evt module (from Carbon import Evt) does not have seem to
Okay so ive been reading up on and working with SQLite recently (someone on
I am currently using the symfony admin-generator a manipulate a database. The database is
Here is the C# code I'm using to launch a subprocess and monitor its
I'm writing an app that's sole purpose is to determine if one of our
I have inherited a Windows service written in C#. Under rare conditions it fails

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.