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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:42:53+00:00 2026-05-28T18:42:53+00:00

I have been wandering about this for some time now. I’m still a beginner,

  • 0

I have been wandering about this for some time now. I’m still a beginner, so my programs are simple and require almost no resources. I’m familiar with C++, Java and C#. But in the future things will get more complicated, with more variables and objects and more functions/methods.

In order to change the value of a variable, I can call a function/method, that changes the value, once. After that when I need the variable, I have to simply call it. It takes less time to get the value. If the function does a lot of work, the time that it has consumed will be experienced only once. But the variables require space in the memory and when their quantity gets quite big, this can become a problem.

But I can call a function/method that returns the value I need. I will only need to use variables where necessary, which means- less variables. It’s not a problem if the function/method is short. But some functions/methods must do quite a lot of work before they return the value. This way the program will seem slower for the user.

My question is: memorizing values in variables VS using functions/methods that return the value: which is better, when and why?

This question sounds like: high speed and more consumed memory VS less consumed memory and low speed…

  • 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-28T18:42:53+00:00Added an answer on May 28, 2026 at 6:42 pm

    It is usually wise to avoid caching values which can be computed, since then you can avoid having to maintain state in separate places (and breaking consistency if you eventually forget).

    It is a good idea to abstract away on the calculation of some value (like hiding it behind a function). Later once your code works and you feel it slow, then use profiling to determine the hotspots. If such a function turns out to be a hotspot, you can introduce caching / memoizing underneath, and the abstraction (in an ideal world) will cover the nasty details from the client (of the function).

    Memoization

    Memoizing a function usually involves a lookup table (based on array, associative array, etc.) with a key type being the aggregate of the arguments of the memoized function, and the stored value being the return value of the function.

    Then, the function would first check if the result is already available in the lookup table and return it, or else compute the result and store it before returning.

    In fact, such memoization could be disjoined from the memoized function, and implemented as a separate layer (wrapping the function) if the programming language supports such abstraction. In languages without first-class functions, this can usually be achieved using interfaces and single-method classes.

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

Sidebar

Related Questions

I've been wondering about this for some time. In CouchDB we have some fairly
I have been using Eclipse CDT for some time now, and I love it,
Been using PHP for quite some time now and I was wondering what this
A quick question I've been wondering about for some time; Does the CPU assign
I have been using Python for about a year now, coming from a mostly
This is a question that I have been pondering for a long time ,
I have been wondering for some time how does Google translate(or maybe a hypothetical
I have been wondering about temp tables in sp's and how all that can
I have been wondering about the reload() function in python, which seems like it
Something I have been wondering about properties for a while. When you are using

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.