memory heap allocation

Status
Not open for further replies.

simone

Beta member
Messages
2
I use this code for file opening and allocating heap memory:


std::ifstream in;
const char * buffer;
long ptr;
long size;
std::vector<OBJ_T *> objects_list; // list of objects readed by file


int open_file(string Pfile)
{
ptr=0;
in.open(Pfile.c_str());
if (!in.is_open()) die ("Error, could not open ");
in.seekg (0, ios::beg);
long l = in.tellg();
in.seekg (0, ios::end);
long m = in.tellg();
size=m-l;
buffer=new char[size];
in.seekg (0, ios::beg);
in.read ((char *)buffer, size);
return 0;
};


Later in my project, i do a "parsing" in "Pfile" (now in memory heap) and I allocate other memory heap (using 'new') for other objects that I create.
In execution, I get "segmentation fault" error (I work with linux version 9).
Where is my error?
I allocate enough memory or not?
Sorry for my english!
Thank you very much.
 
Status
Not open for further replies.
Back
Top Bottom