Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 99361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T00:22:22+00:00 2026-05-11T00:22:22+00:00

I am inputting a 200mb file in my application and due to a very

  • 0

I am inputting a 200mb file in my application and due to a very strange reason the memory usage of my application is more than 600mb. I have tried vector and deque, as well as std::string and char * with no avail. I need the memory usage of my application to be almost the same as the file I am reading, any suggestions would be extremely helpful. Is there a bug that causes so much memory consumption? Could you pinpoint the problem or should I rewrite the whole thing?

Windows Vista SP1 x64, Microsoft Visual Studio 2008 SP1, 32Bit Release Version, Intel CPU

The whole application until now:

#include <string> #include <vector> #include <iostream> #include <iomanip> #include <fstream> #include <sstream> #include <iterator> #include <algorithm> #include <time.h>    static unsigned int getFileSize (const char *filename) {     std::ifstream fs;     fs.open (filename, std::ios::binary);     fs.seekg(0, std::ios::beg);     const std::ios::pos_type start_pos = fs.tellg();     fs.seekg(0, std::ios::end);     const std::ios::pos_type end_pos = fs.tellg();     const unsigned int ret_filesize (static_cast<unsigned int>(end_pos - start_pos));     fs.close();     return ret_filesize; } void str2Vec (std::string &str, std::vector<std::string> &vec) {     int newlineLastIndex(0);     for (int loopVar01 = str.size(); loopVar01 > 0; loopVar01--)     {         if (str[loopVar01]=='\n')         {             newlineLastIndex = loopVar01;             break;         }     }     int remainder(str.size()-newlineLastIndex);      std::vector<int> indexVec;     indexVec.push_back(0);     for (unsigned int lpVar02 = 0; lpVar02 < (str.size()-remainder); lpVar02++)     {         if (str[lpVar02] == '\n')         {             indexVec.push_back(lpVar02);         }     }     int memSize(0);     for (int lpVar03 = 0; lpVar03 < (indexVec.size()-1); lpVar03++)     {         memSize = indexVec[(lpVar03+1)] - indexVec[lpVar03];         std::string tempStr (memSize,'0');         memcpy(&tempStr[0],&str[indexVec[lpVar03]],memSize);         vec.push_back(tempStr);     } } void readFile(const std::string &fileName, std::vector<std::string> &vec) {     static unsigned int fileSize = getFileSize(fileName.c_str());     static std::ifstream fileStream;     fileStream.open (fileName.c_str(),std::ios::binary);     fileStream.clear();     fileStream.seekg (0, std::ios::beg);     const int chunks(1000);      int singleChunk(fileSize/chunks);     int remainder = fileSize - (singleChunk * chunks);     std::string fileStr (singleChunk, '0');     int fileIndex(0);     for (int lpVar01 = 0; lpVar01 < chunks; lpVar01++)     {         fileStream.read(&fileStr[0], singleChunk);         str2Vec(fileStr, vec);     }     std::string remainderStr(remainder, '0');     fileStream.read(&remainderStr[0], remainder);     str2Vec(fileStr, vec);       } int main (int argc, char *argv[]) {            std::vector<std::string> vec;         std::string inFile(argv[1]);         readFile(inFile, vec); } 
  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T00:22:23+00:00Added an answer on May 11, 2026 at 12:22 am

    Your memory is being fragmented.

    Try something like this :

      HANDLE heaps[1025];   DWORD nheaps = GetProcessHeaps((sizeof(heaps) / sizeof(HANDLE)) - 1, heaps);    for (DWORD i = 0; i < nheaps; ++i)    {     ULONG  HeapFragValue = 2;     HeapSetInformation(heaps[i],                        HeapCompatibilityInformation,                        &HeapFragValue,                        sizeof(HeapFragValue));   } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this form for inputting the birthday in html. But I only have
Is it possible to bring GCC into an infinite loop by inputting strange source
Now i am inputting some data from a form and i have a code
when I run this program while inputting a number greater than 46348, I get
I have a form/subform for inputting data into an ado table. The main form's
I have been given a task of inputting some student data, like option 1:
I have come across some problems when inputting certain characters into my mysql database
I have a script which allows me to lookup for a hostname after inputting
HTML input element has a maxlength attribute, which prevents inputting a text longer than
So I have users inputting numbers into multiple text boxes and I need to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.