How can I write 200kb faster?

Hey guys. I'm currently working on a program that extracts text from a specific game. The program works but it is extremely slow. If I try to extract 200kb of text it takes 2 minutes.

The program extracts text by reading bytes from a file and converting them into letters.

This is the code that converts bytes into letters:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
void BinaryToString(){        //Find the letter/string equivalent of the hex character.


ifstream table (Tablefilename);

while (Byte!=0x0){


Byte=(int)Buffer[BufferPosition]&Mask;
if (Byte==0x0){
break;
}


if (Byte>0x80){        //Increase the pointer by 2 if the letter is an SJIS character.
Pointer=Pointer+0x02;
Buffer0=(int)Buffer[BufferPosition]&Mask;
Buffer1=(int)Buffer[BufferPosition+1]&Mask;
Byte=(Buffer0<<8)|(Buffer1);
BufferPosition=BufferPosition+0x02;

if (PT_Type=="-fl"){
TextAddress=TextAddress+0x02;}
}
else if (Byte<0x80&Byte!=0x0){  //Increase the pointer by 1 if the letter is an Ascii character.
Pointer=Pointer+0x01;
BufferPosition=BufferPosition+0x01;
if (PT_Type=="-fl"){
TextAddress=TextAddress+0x01;}
}

while (getline(table,line)){           //Read the table file line by line; until the letter is found.

number=line.substr(0,line.find('='));  //Save the number of the table string.
letter=line.erase(0,line.find('=')+0x1); //Save the letter of the table string.



stringstream str;
str<<hex<<number;
str>>hex>>tablebyte;


if (tablebyte==Byte){              //Do this routine once the correct letter has been found.

TextString=TextString+letter;
table.close();
BinaryToString();




}
}}
}


It then writes every string into a buffer and puts it into an output file.

Here's the code that writes the string buffer to a file:
outfile<<output;

It's fine for small 1kb files, but how can I make my code write 200kb faste
Last edited on
What is the meanon of the recursion on line 48?

You get the same byte again and again. I don't see how this will supposed to end at all (once line 44 is true)?
Topic archived. No new replies allowed.