Re: Swap templat
From: Thomas Matthews (Thomas_MatthewsSpitsOnSpamBots_at_sbcglobal.net)
Date: 06/28/04
- Next message: Jeff Hill: "specialized constructor arg signitaure for const object"
- Previous message: Chris Theis: "Re: New Programmer..."
- In reply to: JKop: "Swap templat"
- Next in thread: JKop: "Re: Swap templat"
- Reply: JKop: "Re: Swap templat"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 28 Jun 2004 17:46:50 GMT
JKop wrote:
> Imagine a class that is absolutely massive in memory, maybe even a MB. You
> want to swap two of these classes, and so obviously you don't want a
> temporary. What do yous think of the following? I ain't got a compiler at
> the moment so it's untested, and may be syntactically incorrect in places.
Generally, when classes, objects, instances or data is massive
in memory, you want to avoid swapping the beasts. Most programmers
use pointers to massive data and just swap the pointers.
If you don't want to use a temporary variable, then try swapping
individual members of the classes. One would say that less
memory is used swapping a class' member than the whole class.
This could even trickle down for aggregate and sub-classes.
Again, ask yourself why you are swapping the monstrosities
rather than pointers to them.
--
Thomas Matthews
C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
- Next message: Jeff Hill: "specialized constructor arg signitaure for const object"
- Previous message: Chris Theis: "Re: New Programmer..."
- In reply to: JKop: "Swap templat"
- Next in thread: JKop: "Re: Swap templat"
- Reply: JKop: "Re: Swap templat"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|