C++/64-bit compilation
Expert: Joseph Moore - 8/12/2009
QuestionQUESTION: I have written this code:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <fstream>
#include <stdlib.h>//(for atoi to work)
using namespace std;
void usage()
{
cout << "Usage: <input1> <input2> <output>\n";
cout << "\n see README for more details.\n";
exit(1);
}
int main(int argc, char *argv[])
{
cout << "\nshmoosh - concatenates and uniques wordlists into one\n";
if(argc!=4)
usage();
vector<string> vec_wordlist_compilation;
///////////////////////////input1//////////////////////////////
ifstream wordlistfile(argv[1]);
if(!wordlistfile.is_open())
{
cout<<"\nError opening file \'"<<argv[1]<<"\'\n";
exit(1);
}
int x=0;
string word;
while(getline(wordlistfile,word)){
vec_wordlist_compilation.push_back(word);
x++;
}
cout << x << " words loaded from file \'"<<argv[1]<<"\'\n";
wordlistfile.close();
///////////////////////////input2//////////////////////////////
ifstream wordlistfiletwo(argv[2]);
if(!wordlistfiletwo.is_open())
{
cout<<"\nError opening file \'"<<argv[2]<<"\'\n";
exit(1);
}
int v=0;
while(getline(wordlistfiletwo,word)){
vec_wordlist_compilation.push_back(word);
v++;
}
cout << v << " words loaded from file \'"<<argv[2]<<"\'\n";
wordlistfiletwo.close();
////////////////////////////sort//////////////////////////////
cout << "\nsorting " << v+x << " words, removing duplicates...\n";
//sort vector (least to greatest)...
sort(vec_wordlist_compilation.begin(),vec_wordlist_compilation.end());
//remove duplicates...
vec_wordlist_compilation.resize((unique(vec_wordlist_compilation.begin(),vec_wordlist_compilation.end()))-vec_wordlist_compil
ation.begin());
/*for(unsigned int c=0;c<vec_wordlist_compilation.size();c++)
cout << vec_wordlist_compilation[c] << "\n";*/
cout << vec_wordlist_compilation.size() << " unique words remain.\n";
////////////////////////////output//////////////////////////////
ofstream output(argv[3]);
for(unsigned int c=0;c<vec_wordlist_compilation.size();c++)
output << vec_wordlist_compilation[c] << "\n";
return 0;
}
it's purpose is to join two wordlists into one and remove duplicate words. The problem is, being a 32-bit program, it can only access 2GB of my 8GB of RAM. I want to compile it in 64-bit mode, enabling it to access all of my RAM.
First off, can this code be compiled in 64-bit mode? Would I have to actually modify the source code?
Second, I was told that it was impossible to configure my compiler (Microsoft Visual C++ 2008 Express Edition) to compile in 64-bit mode. I was told I would have to purchase Professional Edition. Is this true? If it is true, and compilation in 64-bit mode is as simple as compiler reconfiguration, I was wondering if you could find time to compile this code in 64-bit mode using professional edition, since I cannot afford it. It uses the BigInteger library (
http://mattmccutchen.net/bigint/)and I think the BigInteger library is 64-bit capable, but I may be wrong.
Of course, if it is more complicated than this, I understand and will look somewhere else.
ANSWER: Visual Studio Express edition does not include 64-bit compilation, you are correct. There are certain options (such as the 64-bit compiler) that are only included in Visual Studio Professional. If you happen to be a student, I recommend getting a student-discount copy of Visual Studio Professional. I'm going to try to compile the code into a 64-bit executable for you, and barring that, I'll see if I can't find a way for you to compile 64-bit on your own without requiring VS Pro. Please send me a followup so that I can get the results back to you.
---------- FOLLOW-UP ----------
QUESTION: thank you. Yeah, actually, the program doesn't use the BigInteger library at all. I am just so used to using it in my applications - I must have been looking at the source for something else. I heard GNU G++ can compile in 64-bit mode, but I need a Windows executable and I don't know if I can do that. If you make any modifications to the source, could you send that, too? Thank you for your time!
AnswerOK, I compiled a debug and a release version. I didn't have to touch the source code at all, and I did verify that it's a 64-bit exe. The files have been rared together and stored here:
http://www.filedropper.com/x64
Let me know if you need anything else!