Re: Swap templat

From: Thomas Matthews (Thomas_MatthewsSpitsOnSpamBots_at_sbcglobal.net)
Date: 06/28/04


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


Relevant Pages

  • Re: Swapping even when turned off?
    ... P.S. I've got 4GB of RAM, with 2GB swap files on each of two physical hard ... > Swapping memory is used for one thing and one thing only: ... > Swapping them out would free memory, but that memory would not be used, ... >> What on earth would prompt someone to turn off the swap file. ...
    (microsoft.public.windowsxp.general)
  • Re: Keys get stuck
    ... Swap can definitely keep X off the cpu for extended periods, ... A heavily swapping machine ... Seems ou use too much memory then. ...
    (Linux-Kernel)
  • Re: swap space size
    ... I believe this was just a rule of thumb when memory was so expensive. ... And if it stops swapping, ... "two times 'so much'" swap space have? ...
    (Debian-User)
  • Re: why swap at all?
    ... swap, but it is usually a good idea. ... Please note that your machine _will_ do one kind of swapping even if you ... if memory pressure happens then your programs will be evicted ... you're better off with a swap partition because then it is the least used ...
    (Linux-Kernel)
  • Re: 2.6.9-rc2-mm1 swsusp bug report.
    ... > Pavel> Out of memory... ... I almost never touch swap. ... Read FAQ. ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)