Results 1 to 4 of 4

Thread: Vector and memory

  1. #1

    Thread Starter
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024

    Vector and memory

    I have a struct:
    struct UT210
    {
    string sLID;
    string sCID;
    };

    And a vector that uses the struct:
    vector<UT210> vecUT210AP;

    And a temp var in my function:
    UT210 stUT210;

    That takes in results from an sql fetch, which does a select * from the table:

    Code:
    while ( !g_bBottomRecord)
    { 
       i++;
       stUT210.sLID = (char*)m_Data[1];
    
       stUT210.sCID = (char*)m_Data[0];
    
       vecUT210AP.push_back(stUT210);
       Fetch();
    }
    In total there are around 34,000 records to be taken in.

    The problem I have is that I get an out of memory error, which I am going to guess is caused by the increasing of the vector. So am I doing something wrong here? Is there a better way to do this? Am I just putting to much data into this vector.

    Oh my machine is a 3GHz HT w/ 4GB of RAM so I doubt that its my machine.
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  2. #2
    Member
    Join Date
    Sep 2001
    Posts
    42
    Hi!!

    If m_Data array already has data stored in it and m_Data is not being deleted after copying the data in the vector then it is better to store the address(pointer) to respective data than to store the whole data. That may solve the memory problem

    Regards
    Shaunak

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Also you should try to find out the number of rows and use vector::reserve to allocate memory in advance to speed things up.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  4. #4

    Thread Starter
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    Did that already and it helped alot. I was also leaking a little on the fetch which wasn't helping.
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width