Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Closed Thread
Old 02-24-2004, 05:43 AM   #1 (permalink)
 
Newb Techie

Join Date: Feb 2004

Posts: 2

simone

Question memory heap allocation

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.
simone is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On