TechBar.gif (12564 bytes)

15 Ways To Make Your C++ Code More Efficient

 

Interesting Links to

C++

C

UNIX

LINUX

JAVA

HTML

Journals

Networking

 

15 Ways To Make Your C++ Code More Efficient

1. Use new and delete instead of malloc and free

2. Make sure that you acll delete on pointer members in the destructor

3. Check return value of new. The better solution is to install a new handler so that you need not worry about checking the value whenever you do a new

4. If you overload the new operator in your class write overloaded delete also

5. If your class has pointer member variables, put in other words if your class has dynamically allocated memory, write a copy constructor and Assignment operator.

6. While writing constructors, prefer initialization to assignment. Try to make use of member initialization list. Always use the list members in the order they are declared in the class. There are some instances where you have to use member initialization list, like initializing const member variables.

7. Make destructor virtual in base classes

8. Try to avoid public data members

9. Use const members whenever possible

10. If you pass or return objects, use reference than value

11. Don’t return a reference when you must return an object. If you need a new object, you have to.

12. Never return a reference/pointer to a local object

13. Prefer compile time and link time errors to runtime errors

14. Initialize all global objects/variables before use

15. Don’t ignore Compiler warnings

 

Memory Management and C++

Rule 1: Use new and delete People who are more familiar with C often tend to use malloc() and free() to allocate and deallocate memory. Why is it beneficial to use new and delete in C ? Well, there is couple of good reasons for that. First, new calls the constructor of a class to initialize it. If you use malloc(), you need to do that explicitly by calling calloc(). The same holds good for delete(). Delete() calls the destructor of the class to de-allocate the memory. Secondly, if new() fails for any reason, you can handle it effectively using new handler. C has the provision of new handler. We will come to that later in this article.

Rule 2: Write a Copy Constructor and/or Assignment operator for classes which have pointer member variables This is very important. Let us see what happens if we don’t have a proper assignment operator in the class. Consider the following class:

class CTemp { private: char* pszName; …. }

void SomeFunction(CTemp& cTemp); { CTemp local; local = cTemp; … }

Look at the assignment. We will have a problem here. Since we don’t have an assignment operator, the compiler does a copy by value. Note that the value of the pointers are copied. So now we have two classes pointing to the same data and at the same time both instances doesn’t know that the other class is referring to the same data. So if “local” deallocate the string you will have cTemp’s string pointing to some garbage. To avoid this kind of problems, we should have an assignment operator and/or a copy constructor which actually does a copy, not of the pointer values, but of the contents of the location pointed to by that pointer.

Now, what is the difference between a copy constructor and an overloaded assignment operator ? They look same. They do similar operations. Both copy the state of one object to another. Then, what’s the difference ? Well, the main difference is that copy constructor creates a new object where as assignment operator copies the state of one object another existing object. So, the assignment operator obviously has to take care of the current state of the object also. In most cases the current state doesn’t matter, but there could be scenarios where this happens.

Rule 3: Don’t use memcpy() This function operates on bytes. It doesn’t operate on classes. So you will have to start worry about the amount of memory to copy etc, which you definitely are not bothered about.

Top

UNIX URLs

1.UNIX Socket FAQ http://www.ibrado.com/sock-faq/

2.UNIX man pages http://www.ntua.gr/cgi-bin/man-cgi

3.UNIX Reference Desk http:// www.geek-girl.com/unix.html

4.Introduction to Unix http://wks.uts.ohio-state.edu/unix_course/intro-1.html

5.Unix Guru Universe http://www.ugu.com/

6.Introduction to the UNIX Operating System http://riceinfo.rice.edu/Computer/Documents/Unix/UNIX1/unix1.html

7.Unix System Administration http://www.webring.org/cgi-bin/webring?ring=ugu&list

8. Manual Pages http://www.ugu.com/sui/ugu/show?I=help.man&F=1111111111&G=Y

Top

LINUX

1.Linux Applications and Utilities Page - Programming http://www.xnet.com/~blatura/linapp6.html

Top

C++

1.C/C++ Resources (Internet Resources for Windows Developers) http://www.r2m.com/windev/cpp-compiler.html

2. C/C++ Tutorials http://www.genitor.com/resources/tutorial.htm

3.C/C++ Tutorials http://www.flamingolingo.com/programming.c/Tutorials

4.DevCentral Learning Center http://devcentral.iftech.com/learning/tutorials/

5.Home of Kazlib http://users.footprints.net/~kaz/kazlib.html

6.LEARN C/C++ TODAY http://www.cyberdiem.com/vin/learn.html

7.Tutorial & Help classes http://www.taxpolicy.com/tutorial/

8.C++ Annotations Ver 4.4 http://www.icce.rug.nl/docs/cplusplus/cplusplus.html

9.Sources on C and C++ http://www.lysator.liu.se/c/c-www.html

Top

HTML

1. HTML Station--Welcome http://www.december.com/html/

2.HTML: An Interactive Tutorial for Beginners http://davesite.com/webstation/html/

3. HTML Resource Index http://edtech.nepean.uws.edu.au/html/index.htm

Top

C

1.C links http://icfst.kiev.ua/panorama/Links/c.htm

2. C Language Tutorial http://www.swcp.com/~dodrill/cdoc/clist.htm

3. Programming in C(Dave Marshall) http://www.cm.cf.ac.uk/Dave/C/CE.html

4.Source Code Archives http://www.program.com/source/index.html

5.C PROGRAMMING resources from Nerd World Media http://www.nerdworld.com/nw93.html

6.CSourceCode   http://home.ici.net/~sj/cprogram.htm

7.C Programming : http://www.eskimo.com/~scs/cclass/cclass.html

8.A Tutorial on Pointers and Arrays in C http://pweb.netcom.com/~tjensen/ptr/pointers.htm

Top

JAVA

1.Java Repository:Resource Collection for Java Programmers http://java.wiwi.uni-frankfurt.de:8080/java/owa/jr_resourcelist_SRC

2. Programmer's source : Java Resource http://www.progsource.com/java.html

3. Web Publishing Examples http://www.authors.com Java Script World http://www.jsworld.com

4.Java Prog.Resources http://www.apl.jhu.edu/~hall/java

5.Programmer's Heaven http://www.ProgrammersHeaven.com

6. Thinking In Java(Free Download of the whole book) http://www.MindView.net/javabook.html

7. Java Developer Connection:Articles http://developer.java.sun.com/developer/technicalArticles

8.Java Docs & Training http://developer.java.sun.com/developer/infodocs/

9.Java World :http://javaworld.com/

Top

Technical Reports,Publications from Journals and Online Computer Magazines URLs

1.Java'98 Workshop Advance Program http://www.cs.ucsb.edu/conferences/java

2.Java Workshop Special Issue Submitted Papers http://www.npac.syr.edu/users/gcf/03/jav

3.Technical Reports, Computer Science, UCSB http://www.cs.ucsb.edu/TRs/

4.World Wide Web Conferences http://www.w3.org/Conferences/Overview-WWW.html

5.UMKC - CST - Technical Support http://www.cstp.umkc.edu/tech/

6.Web caching bibliography http://www-sor.inria.fr/projects/relais/biblio/

7.The Collection of Computer Science Bibliographies h

8.ACM Digital Library Table of Contents http://www.acm.org/dl/toc.html

9.IEEE Internet Computing : http://computer.org/internet

10.Computer Networks and ISDN Systems : http://www.elsevier.nl/locate/comnet

11.Windows Developer Journal : http://www.wdj.com/home

12.Windows NT FAQ : http://www.ntfaq.com

13.Journal of Network and Compter Applications : http://www.iicm.edu/jnca

14.International Journal of Network Management :. http://www.wiley.com/journals/nem

15.Internet Week : http://www.internetwk.com

16.Express Computer : http://www.expressindia.com/bpd/ec

17.Visual C++ Developer's Journal : http://www.vcdj.com

18.Microprocessor report : http://www.chipanalyst.com/report/mpr.html

19.ORACLE magazine : http://www.oramag.com

20.Byte Magazine : http://www.byte.org

21.Java World : http://www.javaworld.com

22.Web Reference : http://www.webreference.com

23.PC Computing : http://www.zdnet.com/pccomp/

24.Computer World : http://www.computerworld.com

25.Sun World Online : http://www.sun.com/sunworldonline/index.html

26.Datamation : http://www.datamation.com

27.Data Communications Magazine : http://www.data.com

28.Dr.Dobb's Journal : http://www.ddj.com

29.Linux Journal : http://www.ssc.com/lj/

30.Web Developer : http://www.webdeveloper.com

31.Windows NT Magazine : http://www.winntmag.com

31.Web techniques : http://www.webtechniques.com

32.Network Computing : http://www.networkcomputing.com

33.Network Magazine : http://www.networkmagazine.com

34.Java Pro : http://www.java-pro.com

35.University of Stanford(EE/CS Mother site): http://ee.stanford.edu/eesites

36.Aline BAGGIOS bookmarks on Mobile Computing : http://www-sor.inria.fr/~aline/mobile/biblio.html

37.Some more pointers to Mobile Computing : http://www-sor.inria.fr/~aline/mobile/mobile.html

38.IEEE Communications Society : http://www.comsoc.org

39. IEEE Computer Society : http://www.computer.org

40.Windows NT Internals : http://www.sysinternals.com

Top

Network Management URLs

1.Simple Times magazine : http://www.simple-times.org

2.International Journal of Network Management Home page : http://www.wiley.com/nem

3.Network Management resource database : http://www.cforc.com/cwk/net-manage.cgi

4.SNMP research: http://www.snmp.com

5.Network Management consortium : http://www.iol.unh.edu/consortiums/netmgt/index.html

6.Network Management Resource site : http://netman.cit.buffalo.edu/index.html

7.University of Twente,Netherlands home page: http://wwwsnmp.cs.utwente.nl

8.Java Based Network Management : http://www.mindspring.com/~jlindsay/webased.html

9.RFCs related to Network Management : http://wwwsnmp.cs.utwente.nl/Docs/ietf/rfc/rfcbytopic.shtml

10.Network Management White paper: http://smurfland.cit.buffalo.edu/NetMan/Doc/DStevenson

11.MIBs for any SNMP device: http://smurfland.cit.buffalo.edu/ftp/pub/mibs

12.Network Management Forum : http://www.nmf.org

Top

[Home] [Personal] [Nostalgia] [India] [Kerala] [Songs] [Search] [Contact Me] [Sign Guestbook] [View Guestbook]

Visitors Since Nov 22 1999
FastCounter by LinkExchange

Copyright © 1999 by Rajeev M. All rights reserved.
Revised: 20 Nov 1999 01:30:19 India Standard Time.