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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T22:41:17+00:00 2026-05-12T22:41:17+00:00

UPDATE The main questions remain the ones under the example, but I guess it

  • 0

UPDATE
The main questions remain the ones
under the example, but I guess it boils down
to :

**If you have a type where 99% of the values could be represented in one
fast, powerfull type, and only 1% in a
very heavy type, (say int vs.
BigInteger) How to represent it?? **

A school we learned a lot about internal representations, but never how to change it at runtime. I mean : suppose you have a class representing a decimal, but you use an integer to represent it internal, until you actually need a bigger value than the integer, and only than change representation…

I never thought of this before, and when thinkihng of it, I thought that would never work, since all the checks would kill it. But I just did a test since I’m too curious for my own good and there do exist situations when changing of representation is more perormant : given this interface :

interface INumber
    {
        void add1000();
        void SetValue(decimal d);
        decimal GetValue();                     
    } 

I found the latter of the two implementations to be more powerful in a lot of situations, including this one that I composed to attract as many ideas I could on the matter (not rep, it’s community)

    1. Representation by only a decimal

        public class Number1:INumber
        {

            private decimal d { get; set; }


            public void add1000()
            {
                d += 1000;
            }



            public decimal GetValue()
            {
                return d;
            }



            public void SetValue(decimal d)
            {
                this.d = d;
            }

        }


2. Representation by a decimal and an int

public class Number2:INumber
    {
        private bool usedecimal; 
        private int i;
        private decimal d;

        public void add1000()
        {
            if (usedecimal)
            {
                d += 1000;
                return; 
            }

            i += 1000;

            if (i > 2147480000)
            {
                d = i;              
                usedecimal = true;              
            }


        }

        public void SetValue(decimal d)
        {
            try
            {
                i = (int)d;

            }
            catch (OverflowException e)
            {

                this.d = d;
            }

        }

        public decimal GetValue()
        {
            return Math.Max(i,d);
        }
    }
}

My question is the following :

This seems sth. I have been missing, but this must be the bleeding obvious. Can anyone help me out with this?

  • Are there guidelines for mixed representations, when to use them, when not?
  • How to have a hunch when a mixed represtenation can be faster without benchmarking?
  • Any examples?
  • Any patterns?
  • Any ideas on the matter?
  • 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-12T22:41:18+00:00Added an answer on May 12, 2026 at 10:41 pm

    If you have a type where 99% of the values could be represented in one fast, powerfull type, and only 1% in a very heavy type, (say int vs. BigInteger) How to represent it??

    BigInteger implementations typically do exactly that; they keep everything in ints or longs until something overflows, and only then do they go to the heavierweight implementation.

    There’s any number of ways to represent it. A pattern I like is:

    public abstract class Thing
    {
        private class LightThing : Thing
        { ... }
        private class HeavyThing : Thing 
        { ... }
        public static Thing MakeThing(whatever) 
        { /* make a heavy or light thing, depending */ }
        ... etc ...
    }
    

    Are there guidelines for mixed representations, when to use them, when not?

    Sure. We can easily compile such a list. This technique makes sense if:

    (1) the lightweight implementation is much lighter than the heavyweight implementation

    (2) the typical usage falls into the lightweight code path most of the time

    (3) the cost of detecting the transition is not a significant cost compared to the cost of the heavyweight solution

    (4) the more complex two-representation solution is necessary in order to achieve a customer-focused, realistic performance goal.

    How to have a hunch when a mixed represtenation can be faster without benchmarking?

    Don’t. Making performance decisions based on hunches is reasoning in advance of facts. Drive performance decisions on realistic, customer focused, data-driven analysis, not on hunches. If I’ve learned one thing about performance analysis over the years its that my hunches are usually wrong.

    Any examples?

    Any number of implementations of BigInteger.

    Any patterns?

    Beats the heck out of me. I’m not much of one for memorizing pattern taxonomies.

    Any ideas on the matter?

    See above.

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

Sidebar

Related Questions

I have an update program that is completely independent of my main application. I
Sorry I saw similar questions but they don't seem to have some full answers
I have a possibly long running program that currently has 4 processes, but could
I am using a NSProgressIndicator in my main thread to update on progress as
[Update]: my initial example doesn't reflect my problem. Updated the sample, hopfully it is
(update) ICustomTypeDescriptor works for my Windows Forms app, but not for Silverlight; Not supported.
Update: This does work, I was being stupid :( i have the following extension
I know. Heresy. But I'm in a bind. I have a lot of config
I've done extensive research on this, and am baffled. Similar questions on stackoverflow have
I have recently started programming for the iOS Platform but now I need some

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.