CFanatic

Go Back   CFanatic > Programming > C++ Programming

Join CFanatic Forum Now

Does reuse variable make program faster or save some memories? topic posted under C++ Programming which is a part of Programming category in CFanatic Forum
Reply
 
Thread Tools Display Modes
  #1  
Old 09-02-2010, 04:22 PM
Junior Member
 
Join Date: Sep 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
cpthk is on a distinguished road
| More
Does reuse variable make program faster or save some memories?

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?
Reply With Quote
  #2  
Old 09-02-2010, 09:33 PM
shabbir's Avatar
Administrator
 
Join Date: Sep 2006
Posts: 1,163
Thanks: 57
Thanked 63 Times in 44 Posts
shabbir has a spectacular aura aboutshabbir has a spectacular aura about
| More
Re: Does reuse variable make program faster or save some memories?

You are only saving the size of the address storage because any way you are allocating the memory for the variable.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
how can i make a program that counts a number multiple by two vic18 C Programming 1 09-03-2010 12:57 AM
Using variable length variable (bitset) myk45 C++ Programming 0 09-02-2010 01:37 PM
Tracking File Saving using 'Save As' menu options... dinu MFC Programming 0 07-08-2010 01:33 AM
Which is Faster - CArray OR std::vector? ncode MFC Programming 0 06-28-2010 10:55 PM
Hi! how can i save the result screen? pkbis28 C++ Programming 2 05-30-2010 01:34 AM

 

Advertisement

CFanatic Search
Custom Search

Advertisement

All times are GMT -5. The time now is 02:40 AM.



Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO ©2010, Crawlability, Inc.
Cfanatic.com is a premier member of the IDG TechNetwork. For advertising opportunities contact here
Get Paid for Working on Projects Matching Your Expertise at Go4Expert's Jobs Board