1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Does reuse variable make program faster or save some memories?

Discussion in 'C++' started by cpthk, Sep 2, 2010.

  1. cpthk

    cpthk New Member

    Joined:
    Sep 2, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    If I have this code:
    Code:
    void test(){
        Map *m1 = new Map;
        ....
        Map *m2 = new Map;
        ....
    }
    I optimized to:
    Code:
    void test(){
        Map *m1 = new Map;
        ....
        m1 = new Map;
        ....
    }
    
    Does this optimization makes program run slightly faster or save some memories since it does not have to create another variable?
     
  2. NewsBot

    NewsBot New Member

    Joined:
    Dec 2, 2008
    Messages:
    1,267
    Likes Received:
    1
    Trophy Points:
    0
    You are only saving the size of the address storage because any way you are allocating the memory for the variable.
     

Share This Page