Archived

This topic is now archived and is closed to further replies.

Loading Files into mem then working on them prob c/c++

This topic is 5240 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi, Im trying to load a file into memory then work on it but its causing iratic problems and seems very unstable. for example. when i load a file into memory then start readig from it then try to return from the funtion i get an error in the ofstream::~ifstream(){}. also i wrote another funtion that exptrats the data, in that it loads it from the file and works with it the same way, ok. but when run the app and move round it crashes. I checed the code and it seems that pointes are being corupted or something simular. if anyone has ne tips with working with files loaded into memory it would also be apretiated.
char chunk_type[4];
	//BYTE *m_data_start;	//track the begining so we can delete all of the data later
	DWORD file_length;
	BYTE *m_data; 

	//determin file length. assig memory. then load
	ifstream csmFile("pirpe.csm", ios::nocreate | ios::binary);
	csmFile.seekg(0, ios::end);
	file_length = csmFile.tellg();
	m_data = new BYTE[file_length] ;
	if(m_data == NULL) return false;
	//m_data_start = m_data;
	memset(m_data, 0, file_length );
	csmFile.seekg(0, ios::beg);
	csmFile.read((char *)m_data, file_length);
	csmFile.close();

//start reding in stuff
DWORD chunk_size, size = 0;
	BYTE delimiter='A', *data_anchor ;
		
	memcpy(chunk_type, m_data, sizeof(BYTE) *4 );
	m_data += sizeof(BYTE) *4;

	
	memcpy(&chunk_size, m_data, sizeof(DWORD) *4 );
	m_data += sizeof(DWORD) ;

   
[edited by - zerosignull on August 7, 2003 7:45:53 AM] [edited by - zerosignull on August 7, 2003 7:47:42 AM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by Zerosignull
i get an error in the ofstream::~ifstream


ahem,

<b>WHAT ERROR?</b>

and did the file open sucessfully? why you managed to test the new, when it rarely fails, and didn''t test the ifstream, when it fails relatively often....

Share this post


Link to post
Share on other sites
you know what i was talking about "its causing iratic problems and seems very unstable" the damn thing just started working for no reason. the problem it was just making the compiler drop out in to ifstream destructor with the usual null pointer malarky.

The file opens fine. its copied into the buffer fine. its extracted out of the buffer into the variables fine. Just causes crashes for no reason. the closest i can reason it to is memory stomping but im not getting any out of bounds errors by the debuger

[edited by - zerosignull on August 7, 2003 6:31:26 PM]

Share this post


Link to post
Share on other sites