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 6961315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:30:54+00:00 2026-05-27T15:30:54+00:00

The question as what the title says, static functions? or functions of an object

  • 0

The question as what the title says, static functions? or functions of an object that is deleted right away?

I know that in a real situation the difference is completely unnoticable but i would still like to know which is more efficient in saving memory. I really don’t mind the overhead given by the “new” and “delete” command.

MyClass::staticFunction();

or…

myObject = new MyClass;
myObject->normalFunction();
delete myObject;

edit: the second code might as well be MyClass().normalFunction(); silly…

there are a few things to consider here;

  1. there will only be one instance of the myObject, and it is only used ONCE in the application.
  2. after usage, it is deleted right away because it is not needed.
  3. one would ask, why is this even in a class? why not just put the function where it is used with temporary variables? the answer is encapsulation and readability. i do believe static functions use the same resources as global functions since in fact, they really are global functions that enjoy class scope. the only reason i have to put it in it’s own class is to make my code more readable, and encapsulation.
  • 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-27T15:30:54+00:00Added an answer on May 27, 2026 at 3:30 pm

    As it stands, none of this makes any sense. The real solution would be to provide a free function (a function at namespace scope), because this is what free functions are there for.

    Oh, and since you asked: If calling this one single function has noticeable overhead in your code, then you will only find out about it through careful profiling. Profiling is also what would answer your question which way is faster.
    But first make sure your code is easy to read and well maintainable. Optimizing this then will be much easier than fixing prematurely micro-“optimized” code. The only early optimizations you should employ are those that result in optimal data structures and algorithms.

    (Note that new and delete will very likely have far greater overhead than what the function actually does, let alone calling it.)

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

Sidebar

Related Questions

I have a 2 part question. First, as the title says, does anybody know
Just what the question title says. I'm using SpringMVC, but that's irrelevant really. I
As question title says, I need to know how to set the mouse cursor
Quick question here: As the title says, what's the difference between the two events?
As the title says, my problem is that I don't know If/How I can
Question title says it all really - a lot slower than VS2005, with a
I know the question title isn't the best. Let me explain. I do a
I have a quick question. As the title says, I'd like to find a
It's my first question but I'm trying to ask correctly. As the title says
Like the title says, I'm trying to find elements of M that exist in

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.