I am having problems with the new operator() specifically within
std::string
I appear to have hit a memory limit in visual studio.
Ideally I would like someone to help me find one of the following solutions:
1 - Can I access the memory in a very big file directly without a memory buffer?
2 - How do you increase the maximum size of the free store in visual studio?
My approach at the moment is not working I have a very big file that I want to
chop before processing.
- I create a membuffer for a 1Gb file (this was made from 25Gb file)
- then try to use a std::string to iterate over the string.
but I cannnot create the string as I get
bad allocation error
from cstr()
A simplified version of my code
#include <string>
#include <exception>
#include <fstream>
#include <iostream>
void main()
{
std::ifstream fin("D:\\Gig1.txt", std::ios::in);
if(fin.is_open)
{
unsigned int sz(1073741825); // 1 gig (1024)^3
char * memblock = new char[sz]; //this is fine
//check file sz is right size not called as sz == gcount
fin.seekg(0, std::ios::beg);
fin.read(memblock, sz);
if(sz > fin.gcount())
{
sz = fin.gcount();
}
try
{
std::string str(memblock, sz); //too much for visio :(
}
catch(exception &e)
{
std::cout << e.what() << std::endl;
}
delete [] memblock;
fin.close();
}
}
This is an approximate code and I am posting here as my first post was asking the wrong question.
Thanks,
David