Solved

Use of CMap blows up swap file

Posted on 1998-12-08
5
586 Views
Last Modified: 2013-11-20
My program contains a CMap containing 300byte objects. When I load objects from a 600kb file (approx 2000 objects) into memory using CMap::Serialize() the windows swap file (win386.swp) blows completely out of proportion. I need about 2Gb free on my hard drive before the de-serializing works. The file contains approximately two thousand 300byte objects and I would expect the memory needed to be similar in size to the hard disk space needed which is only 600kb. My objects DO NOT allocate any extra memory! Can someone tell why the program needs so much memory.

   Update: The CMap default constructor is below:

   CMap( int nBlockSize = 10 );

   I have been constructing my CMaps with nBlockSize=4096. I assumed the BlockSize is in bytes. At
   this point I am beginning to wonder if it means the number of blocks of system memory. I think
   windows NT has a block size of either 2048 or 4096Bytes which means I may be allocating 4096
   blocks of 2048Bytes for each of the 2000 objects.
0
Comment
Question by:aderounm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 6

Expert Comment

by:snoegler
ID: 1325916
Why do you have deleted your previous question?
0
 

Author Comment

by:aderounm
ID: 1325917
Edited text of question
0
 

Author Comment

by:aderounm
ID: 1325918
Edited text of question
0
 
LVL 8

Accepted Solution

by:
Answers2000 earned 900 total points
ID: 1325919
Read the MFC source

nBlockSize is set to an internal member of CMap (see AFXTEMPL.H) called m_nBlockSize

This is eventually used :-

CPlex* newBlock = CPlex::Create(m_pBlocks, m_nBlockSize, sizeof(CMap::CAssoc));

If you read CPlex::Create in PLEX.CPP, you will see

CPlex* PASCAL CPlex::Create(CPlex*& pHead, UINT nMax, UINT cbElement)
{
      ASSERT(nMax > 0 && cbElement > 0);
      CPlex* p = (CPlex*) new BYTE[sizeof(CPlex) + nMax * cbElement];

Therefore the map allocates up in steps of

sizeof(Cplex) + ( BlockSize *  sizeof CAssoc )

* sizeof(CPlex) is just a few bytes
* CAssoc depends on what's in your map, the struct is also in AFXTEMPL.H
      struct CAssoc
      {
            CAssoc* pNext;
            UINT nHashValue;  // needed for efficient iteration
            KEY key;
            VALUE value;
      };

i.e. 8 + sizeof(KEY) + sizeof(VALUE).

So if your key + value are 300 bytes, then you can see the map increases in steps of =

few bytes + ( 4096 * 308 ) = 1.3 Mb

Basically what this means if you have a map of 0 elements, then you add one, then map growns big enough to allocate 4096 elements.  These get used up (removed from the free list) as you add more stuff, then another 4096 are allocated etc.

Which version of Windows/VC are you using by the way?


0
 

Author Comment

by:aderounm
ID: 1325920
Saved! I wonder how I missed that. I was about 48 hours away from  buying a new hard drive.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
bobThere java chalenge 45 97
xyBalance chalenge 58 105
Turn a spreadsheet into a vba executable. 2 103
string initialization in java 11 122
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question