Expand|Select|Wrap|Line Numbers
- ifstream* seq_input = new ifstream(fname.c_str());
- if(seq_input->is_open()==false) {cerr << "File not found";exit (1);}
- int i, clen=2, pos, str;
- struct data *ndata;
- struct sequence *new_seq;
- ndata=new data;
- ndata->maxlseq=0;
- ndata->nseq=0;
- ndata->type=type;
- ndata->seqs=new sequence*;
-
while(!seq_input->eof()) {
str = seq_input->get();
if ((char)str == '>'){
- string name;
- getline(*seq_input, name);
- int namesizing=name.size();
- new_seq= new sequence;
- new_seq->seq=new int[clen];
- new_seq->name=new char[namesizing];
- new_seq->length = 0;
- new_seq->namesize=0;
- new_seq->namesize=namesizing;
- ndata->nseq++;
- ndata->seqs[ndata->nseq]=new_seq;
- pos=0;
- }
- else if (str == ' ' || str =='\t' || str == '\n') ;
-
else if (ndata->type==1){
pos++;
- switch(str) {
- case '?': case '-':
- ndata->seqs[ndata->nseq]->seq[pos]=0;
- break;
- }
- ndata->seqs[ndata->nseq]->length = pos;
- }
-
if (pos>(clen-10)) {
clen *= 2;
- ndata->seqs[ndata->nseq]->seq = (int *) realloc(ndata->seqs[ndata->nseq]->seq, clen*sizeof(int));
- }
-
if (ndata->seqs[ndata->nseq]->length > ndata->maxlseq) {
ndata->maxlseq=ndata->seqs[ndata->nseq]->length;
- }
- ndata->seqs[ndata->nseq]->length-=1;
- seq_input->close();
- delete seq_input;
Problem #1: Under Visual Studio, I am having problems deleting the pointer to seq_input. I have recently done some memory leak debugging and this is the only leak left. With this code the program crashes on delete seq_input with the error message 'unhandled exception/access violation'. This occurs on the core code line 'sizeNext=pNext->sizeFront'. Any ideas as to why this is happening?
Problem #2: Under Unix command line, the program crashes at the end of the for loop on the line pos=0 with the error message double free or corruption. I haven't deleted anything by this point, so have no idea how to fix this.
Problem 3: To investigate these problems further I tried to download Valgrind but I am having trouble running my (compiled under unix) program on it, it gives me the error message 'can only handle 32-bit executables'
Any suggestions on any of these problems would be hugely appreciated. PS. I know I'm not supposed to use realloc with new/delete. Do you think this is the problem? My coding capabilities don't stretch to working out how not to use it. If I use a vector class instead I can't get it into the structure where it needs to be!
Many thanks...... :)