The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
Please help I am getting this - Unhandled exception at 0x7531812f in testingCodes.exe
Discuss Please help I am getting this - Unhandled exception at 0x7531812f in testingCodes.exe in the C Programming forum on Dev Shed. Please help I am getting this - Unhandled exception at 0x7531812f in testingCodes.exe C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

February 23rd, 2013, 09:31 PM
|
|
Registered User
|
|
Join Date: Feb 2013
Posts: 8
Time spent in forums: 2 h 32 m 42 sec
Reputation Power: 0
|
|
|
Please help I am getting this - Unhandled exception at 0x7531812f in testingCodes.exe
pointing to this code that was triggered by the debugger
pointer allocate(size_type _Count)
{ // allocate array of _Count elements
return (_Allocate(_Count, (pointer)0));
}
I have been on this program pretty much the whole day started it from scratch now i am stuck getting
"Unhandled exception at 0x7531812f in testingCodes.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x00211370.."
but i can't figure it out so before i change some of my codes I will hope someone could point out the problem here.
Thanks in advance...
//This program open three files each has 1000 names that i utilize to create email as many unique email addresses i could get
//2000 first names and 1000 last names i have come to the point where i could generate the email addresses but I still have lef//t to let the user enter how many millions of email wants to generate based on that generate that amount
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <string>
#include <cmath>
using namespace std;
#define MAX 100000
string emails[MAX];
int main()
{
int e, f, ff, gf, i, j, k, l, m, n, num;
char Init[1000];
string STRING1;
string STRING2;
string STRING3;
string adds[5] = {"@hotmail.com", "@yahoo.com", "@gmail.com", "@msn.com", "@excite.com"};
string ffstName[1000];
string gfstName[1000];
string lstNames[1000];
string InitL[1000];
string emailsL[5000];
string emailsI[5000];
ifstream infile1;
ifstream infile2;
ifstream infile3;
infile1.open ("fmlsFName.txt");
infile2.open ("guysFName.txt");
infile3.open ("LstName.txt");
cout << "Enter the number of emails to generate in millions: " ;
cin >> num;
cout <<endl;
int cnt = num * 1000, cntEAd = 1, maxCnt = MAX/(cnt);
//cout <<endl;
//cout << "Here where it starts entering the LADIES email address" <<endl;
//cout <<endl;
//do
//{
while(getline(infile1, STRING1))
{//ff for females first name count
for(ff = 0; ff < 999; ++ff)
{
infile1 >> ffstName[ff];
for(n = 0; n < lstNames[ ff ].size(); ++n)
// InitF[n] = lstNames[n][0];
for(i = 0; i < 5; i++)
{
// cout << ffstName[ff];
// cout << adds[i] <<endl;
}
}
}
//cout <<endl;
//cout << "Here where it starts entering the GUYS email address" <<endl;
//cout <<endl;
//system("pause");
while(getline(infile2, STRING2))
{//gf for guys first name count
for(gf = 0; gf < 999; ++gf)
{
infile2 >> gfstName[gf];
for(n = 0; n < lstNames[ gf ].size(); ++n)
// InitG[n] = lstNames[n][0];
for(i = 0; i < 5; i++)
{
// cout << gfstName[gf];
// cout << adds[i] <<endl;
}
}
}
//cout <<endl;
//cout << "Here where it starts entering email address based on LAST NAME" <<endl;
//cout <<endl;
//system("pause");
while(getline(infile3, STRING3))
{
for(l = 0; l < 999; ++l)
{//l for last name count
infile3 >> lstNames[l];
for(n = 0; n < lstNames[ l ].size(); ++n)
InitL[n] = lstNames[n][0];
for(i = 0; i < 5; i++)
{
// cout << lstNames[l] + adds[i] <<endl;
// cout << Init[n] + adds[i] <<endl;
emailsL[l] = lstNames[l] + adds[i];
emailsI[n] = Init[n] + adds[i];
}
}
}
for(e = 0; e < MAX; e++)
{//e for email address count
emails[e] = emailsL[e];
cntEAd++;
}
cout << "The number of emails generated are: " << cntEAd <<endl;
//}while(cntEAd <= cnt);
/*
for(f = 0; f < num - 1; f++)
{//f for first name count ex: fstName[0] = xy
for(l = 0; l < 999; l++)
{//l for last name count ex: lstName[0] = z
for(i = 0; i < 5; i++)
{//i for email prvdrs count ex:
cout << ffstName[f] + lstNames[l] + adds[i] <<endl;
cout << InitF[f] +"_"+lstNames[l] + adds[i] <<endl;
cout << gfstName[f] + lstNames[l] + adds[i] <<endl;
cout << InitG[f] +"_"+lstNames[l] + adds[i] <<endl;
cout << lstNames[l] + ffstName[f] + adds[i] <<endl;
cout << InitL[l] +"_"+ffstName[f] + adds[i] <<endl;
cout << lstNames[l] + gfstName[f] + adds[i] <<endl;
cout << InitL[l] +"_"+gfstName[f] + adds[i] <<endl;
cout << InitL[l] + "_" + InitF[f] + adds[i] <<endl;
cout << InitL[l] + "_" + InitG[f] + adds[i] <<endl;
}
}
}
*/
infile1.close();
infile2.close();
infile3.close();
system ("pause");
return 0;
}
|

February 24th, 2013, 12:23 AM
|
 |
Lost in code
|
|
|
|
|
What exactly are the results of this program supposed to be used for?
|

February 24th, 2013, 05:10 AM
|
|
Registered User
|
|
Join Date: Feb 2013
Posts: 8
Time spent in forums: 2 h 32 m 42 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by E-Oreo What exactly are the results of this program supposed to be used for? |
Oh, this is my homework assignment basically my grade depends on it... nothing else. Thanks -aK>
|

February 24th, 2013, 12:12 PM
|
 |
Contributing User
|
|
Join Date: Jan 2003
Location: USA
|
|
Two things:
1. Your program is an unreadable mess. It needs to be formatted, indented. And you need to use code tags to preserve that formatting. [code] insert your formatted code here [/code] . For example (getting your original formatting via the Reply button):
Code:
//This program open three files each has 1000 names that i utilize to create email as many unique email addresses i could get
//2000 first names and 1000 last names i have come to the point where i could generate the email addresses but I still have lef//t to let the user enter how many millions of email wants to generate based on that generate that amount
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <string>
#include <cmath>
using namespace std;
#define MAX 100000
string emails[MAX];
int main()
{
int e, f, ff, gf, i, j, k, l, m, n, num;
char Init[1000];
string STRING1;
string STRING2;
string STRING3;
string adds[5] = {"@hotmail.com", "@yahoo.com", "@gmail.com", "@msn.com", "@excite.com"};
string ffstName[1000];
string gfstName[1000];
string lstNames[1000];
string InitL[1000];
string emailsL[5000];
string emailsI[5000];
ifstream infile1;
ifstream infile2;
ifstream infile3;
infile1.open ("fmlsFName.txt");
infile2.open ("guysFName.txt");
infile3.open ("LstName.txt");
cout << "Enter the number of emails to generate in millions: " ;
cin >> num;
cout <<endl;
int cnt = num * 1000, cntEAd = 1, maxCnt = MAX/(cnt);
//cout <<endl;
//cout << "Here where it starts entering the LADIES email address" <<endl;
//cout <<endl;
//do
//{
while(getline(infile1, STRING1))
{//ff for females first name count
for(ff = 0; ff < 999; ++ff)
{
infile1 >> ffstName[ff];
for(n = 0; n < lstNames[ ff ].size(); ++n)
// InitF[n] = lstNames[n][0];
for(i = 0; i < 5; i++)
{
// cout << ffstName[ff];
// cout << adds[i] <<endl;
}
}
}
//cout <<endl;
//cout << "Here where it starts entering the GUYS email address" <<endl;
//cout <<endl;
//system("pause");
while(getline(infile2, STRING2))
{//gf for guys first name count
for(gf = 0; gf < 999; ++gf)
{
infile2 >> gfstName[gf];
for(n = 0; n < lstNames[ gf ].size(); ++n)
// InitG[n] = lstNames[n][0];
for(i = 0; i < 5; i++)
{
// cout << gfstName[gf];
// cout << adds[i] <<endl;
}
}
}
//cout <<endl;
//cout << "Here where it starts entering email address based on LAST NAME" <<endl;
//cout <<endl;
//system("pause");
while(getline(infile3, STRING3))
{
for(l = 0; l < 999; ++l)
{//l for last name count
infile3 >> lstNames[l];
for(n = 0; n < lstNames[ l ].size(); ++n)
InitL[n] = lstNames[n][0];
for(i = 0; i < 5; i++)
{
// cout << lstNames[l] + adds[i] <<endl;
// cout << Init[n] + adds[i] <<endl;
emailsL[l] = lstNames[l] + adds[i];
emailsI[n] = Init[n] + adds[i];
}
}
}
for(e = 0; e < MAX; e++)
{//e for email address count
emails[e] = emailsL[e];
cntEAd++;
}
cout << "The number of emails generated are: " << cntEAd <<endl;
//}while(cntEAd <= cnt);
/*
for(f = 0; f < num - 1; f++)
{//f for first name count ex: fstName[0] = xy
for(l = 0; l < 999; l++)
{//l for last name count ex: lstName[0] = z
for(i = 0; i < 5; i++)
{//i for email prvdrs count ex:
cout << ffstName[f] + lstNames[l] + adds[i] <<endl;
cout << InitF[f] +"_"+lstNames[l] + adds[i] <<endl;
cout << gfstName[f] + lstNames[l] + adds[i] <<endl;
cout << InitG[f] +"_"+lstNames[l] + adds[i] <<endl;
cout << lstNames[l] + ffstName[f] + adds[i] <<endl;
cout << InitL[l] +"_"+ffstName[f] + adds[i] <<endl;
cout << lstNames[l] + gfstName[f] + adds[i] <<endl;
cout << InitL[l] +"_"+gfstName[f] + adds[i] <<endl;
cout << InitL[l] + "_" + InitF[f] + adds[i] <<endl;
cout << InitL[l] + "_" + InitG[f] + adds[i] <<endl;
}
}
}
*/
infile1.close();
infile2.close();
infile3.close();
system ("pause");
return 0;
}
Your poor and inconsistent indentation is another matter that you will need to learn to correct.
2. Since I could not see anywhere that you did any dynamic allocation (the exception seems to indicate that it has something to do with that), then that dynamic allocation must be hidden by a built-in class, such as string. Maybe you're using a string that you had not yet instantiated or otherwise initialized. Knowing which string had triggered this would help immensely.
3. Since this happened while you were in the debugger, that means that you know which line of your code triggered this exception. And yet you are keeping this vital information a secret from us. Do you think that is a wise thing to do when you are asking professionals for free advice? Don't you think that it might be in your own interest to share that secret with us?
|

February 24th, 2013, 12:36 PM
|
|
Registered User
|
|
Join Date: Feb 2013
Posts: 8
Time spent in forums: 2 h 32 m 42 sec
Reputation Power: 0
|
|
I apologize this is my first time here and I didn't know how to submit any of my files. My program is indented but when i copied and paste it here it didn't keep the indentation i had.
Is there a way I could attach images in here, I am not sure if this work but I am trying show you where the endless loop takes place.
[IMG]C:\Users\dell\Documents\Visual Studio 2008\Projects\Project1\testingCodes\debuggingImgs\emailGen.jpg[/IMG]
[IMG]C:\Users\dell\Documents\Visual Studio 2008\Projects\Project1\testingCodes\debuggingImgs\emailGenI.jpg[/IMG]
[IMG]C:\Users\dell\Documents\Visual Studio 2008\Projects\Project1\testingCodes\debuggingImgs\emailGenII.jpg[/IMG]
Hopefully if these images are visible you could see there were 4000 emails generated but the loop crashed after running 5000 times.
Here is where the endless loop is
for(e = 0; e < size; e++)
{cout << "The list of email is " << emailsL[e] ;
cout << " it is inserted in to array [" << e << "]." <<endl;
cout << "The size of generated emails is: " << size <<endl;
emails[e] = emailsL[e];
cntEAd++;
}
Thanks for your valuable time and help.
-aK>
Quote: | Originally Posted by dwise1_aol Two things:
1. Your program is an unreadable mess. It needs to be formatted, indented. And you need to use code tags to preserve that formatting. [code] insert your formatted code here [/code] . For example (getting your original formatting via the Reply button):
Code:
//This program open three files each has 1000 names that i utilize to create email as many unique email addresses i could get
//2000 first names and 1000 last names i have come to the point where i could generate the email addresses but I still have lef//t to let the user enter how many millions of email wants to generate based on that generate that amount
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <string>
#include <cmath>
using namespace std;
#define MAX 100000
string emails[MAX];
int main()
{
int e, f, ff, gf, i, j, k, l, m, n, num;
char Init[1000];
string STRING1;
string STRING2;
string STRING3;
string adds[5] = {"@hotmail.com", "@yahoo.com", "@gmail.com", "@msn.com", "@excite.com"};
string ffstName[1000];
string gfstName[1000];
string lstNames[1000];
string InitL[1000];
string emailsL[5000];
string emailsI[5000];
ifstream infile1;
ifstream infile2;
ifstream infile3;
infile1.open ("fmlsFName.txt");
infile2.open ("guysFName.txt");
infile3.open ("LstName.txt");
cout << "Enter the number of emails to generate in millions: " ;
cin >> num;
cout <<endl;
int cnt = num * 1000, cntEAd = 1, maxCnt = MAX/(cnt);
//cout <<endl;
//cout << "Here where it starts entering the LADIES email address" <<endl;
//cout <<endl;
//do
//{
while(getline(infile1, STRING1))
{//ff for females first name count
for(ff = 0; ff < 999; ++ff)
{
infile1 >> ffstName[ff];
for(n = 0; n < lstNames[ ff ].size(); ++n)
// InitF[n] = lstNames[n][0];
for(i = 0; i < 5; i++)
{
// cout << ffstName[ff];
// cout << adds[i] <<endl;
}
}
}
//cout <<endl;
//cout << "Here where it starts entering the GUYS email address" <<endl;
//cout <<endl;
//system("pause");
while(getline(infile2, STRING2))
{//gf for guys first name count
for(gf = 0; gf < 999; ++gf)
{
infile2 >> gfstName[gf];
for(n = 0; n < lstNames[ gf ].size(); ++n)
// InitG[n] = lstNames[n][0];
for(i = 0; i < 5; i++)
{
// cout << gfstName[gf];
// cout << adds[i] <<endl;
}
}
}
//cout <<endl;
//cout << "Here where it starts entering email address based on LAST NAME" <<endl;
//cout <<endl;
//system("pause");
while(getline(infile3, STRING3))
{
for(l = 0; l < 999; ++l)
{//l for last name count
infile3 >> lstNames[l];
for(n = 0; n < lstNames[ l ].size(); ++n)
InitL[n] = lstNames[n][0];
for(i = 0; i < 5; i++)
{
// cout << lstNames[l] + adds[i] <<endl;
// cout << Init[n] + adds[i] <<endl;
emailsL[l] = lstNames[l] + adds[i];
emailsI[n] = Init[n] + adds[i];
}
}
}
for(e = 0; e < MAX; e++)
{//e for email address count
emails[e] = emailsL[e];
cntEAd++;
}
cout << "The number of emails generated are: " << cntEAd <<endl;
//}while(cntEAd <= cnt);
/*
for(f = 0; f < num - 1; f++)
{//f for first name count ex: fstName[0] = xy
for(l = 0; l < 999; l++)
{//l for last name count ex: lstName[0] = z
for(i = 0; i < 5; i++)
{//i for email prvdrs count ex:
cout << ffstName[f] + lstNames[l] + adds[i] <<endl;
cout << InitF[f] +"_"+lstNames[l] + adds[i] <<endl;
cout << gfstName[f] + lstNames[l] + adds[i] <<endl;
cout << InitG[f] +"_"+lstNames[l] + adds[i] <<endl;
cout << lstNames[l] + ffstName[f] + adds[i] <<endl;
cout << InitL[l] +"_"+ffstName[f] + adds[i] <<endl;
cout << lstNames[l] + gfstName[f] + adds[i] <<endl;
cout << InitL[l] +"_"+gfstName[f] + adds[i] <<endl;
cout << InitL[l] + "_" + InitF[f] + adds[i] <<endl;
cout << InitL[l] + "_" + InitG[f] + adds[i] <<endl;
}
}
}
*/
infile1.close();
infile2.close();
infile3.close();
system ("pause");
return 0;
}
Your poor and inconsistent indentation is another matter that you will need to learn to correct.
2. Since I could not see anywhere that you did any dynamic allocation (the exception seems to indicate that it has something to do with that), then that dynamic allocation must be hidden by a built-in class, such as string. Maybe you're using a string that you had not yet instantiated or otherwise initialized. Knowing which string had triggered this would help immensely.
3. Since this happened while you were in the debugger, that means that you know which line of your code triggered this exception. And yet you are keeping this vital information a secret from us. Do you think that is a wise thing to do when you are asking professionals for free advice? Don't you think that it might be in your own interest to share that secret with us? |
|

February 24th, 2013, 01:00 PM
|
 |
Contributing User
|
|
Join Date: Jan 2003
Location: USA
|
|
Quote: | Originally Posted by soccerstr I apologize this is my first time here and I didn't know how to submit any of my files. My program is indented but when i copied and paste it here it didn't keep the indentation i had. |
These pages use HTML, which strips away extra spaces. That is what HTML does, which is why we need to use code tags to tell HTML to not do that.
Quote: | Originally Posted by soccerstr Is there a way I could attach images in here, I am not sure if this work but I am trying show you where the endless loop takes place.
[IMG]C:\Users\dell\Documents\Visual Studio 2008\Projects\Project1\testingCodes\debuggingImgs\emailGen.jpg[/IMG]
[IMG]C:\Users\dell\Documents\Visual Studio 2008\Projects\Project1\testingCodes\debuggingImgs\emailGenI.jpg[/IMG]
[IMG]C:\Users\dell\Documents\Visual Studio 2008\Projects\Project1\testingCodes\debuggingImgs\emailGenII.jpg[/IMG]
Hopefully if these images are visible ... |
Well, dell (since that is your user name on your computer), those files are all on your local hard drive, Volume C:. We do not have access to your hard disk.
I don't know about this forum, but on others I've seen where you upload a graphics file to another site and then provide the IMG tag with a URL to that file on that other site. I've also seen forums where you can upload a graphic directly, but there usually limits to size.
Quote: | Originally Posted by soccerstr ... you could see there were 4000 emails generated but the loop crashed after running 5000 times.
Here is where the endless loop is |
OK, I think I can see the problem now. Your computer, big and powerful though it may be, has finite limitations. When you run your program, Windows gives it a large amount of RAM to run in and it gives it a generous sized heap to dynamically allocate from, but those resources are still finite and therefore limited. When you run an endless loop which keeps allocated more and more resources from a finite and limited pool of resources, you eventually reach a point where you have used up all those resources. When you have used up all the heap and you try to allocate from it again, you will get an exception.
A question about your code (formatting corrected):
Code:
for(e = 0; e < size; e++)
{
cout << "The list of email is " << emailsL[e] ;
cout << " it is inserted in to array [" << e << "]." <<endl;
cout << "The size of generated emails is: " << size <<endl;
emails[e] = emailsL[e];
cntEAd++;
}
What is size? Are you doing something to increase the value of size while in the for loop? This did not exist in your original listing.
|

February 24th, 2013, 01:11 PM
|
|
Registered User
|
|
Join Date: Feb 2013
Posts: 8
Time spent in forums: 2 h 32 m 42 sec
Reputation Power: 0
|
|
Yes, I apologize again I have been trying fix it pretty much the whole day.... I am trying allocate the size dynamically based on the amount of the emails generated.
Here is the code I used right before the loop
Code:
int size=sizeof emailsL/sizeof(int); //total size of array/size of array data type cout<<size;
I am really appreciative of your time and help.
Regards,
-aK>
Quote: | Originally Posted by dwise1_aol These pages use HTML, which strips away extra spaces. That is what HTML does, which is why we need to use code tags to tell HTML to not do that.
Well, dell (since that is your user name on your computer), those files are all on your local hard drive, Volume C:. We do not have access to your hard disk.
I don't know about this forum, but on others I've seen where you upload a graphics file to another site and then provide the IMG tag with a URL to that file on that other site. I've also seen forums where you can upload a graphic directly, but there usually limits to size.
OK, I think I can see the problem now. Your computer, big and powerful though it may be, has finite limitations. When you run your program, Windows gives it a large amount of RAM to run in and it gives it a generous sized heap to dynamically allocate from, but those resources are still finite and therefore limited. When you run an endless loop which keeps allocated more and more resources from a finite and limited pool of resources, you eventually reach a point where you have used up all those resources. When you have used up all the heap and you try to allocate from it again, you will get an exception.
A question about your code (formatting corrected):
Code:
for(e = 0; e < size; e++)
{
cout << "The list of email is " << emailsL[e] ;
cout << " it is inserted in to array [" << e << "]." <<endl;
cout << "The size of generated emails is: " << size <<endl;
emails[e] = emailsL[e];
cntEAd++;
}
What is size? Are you doing something to increase the value of size while in the for loop? This did not exist in your original listing. |
|

February 24th, 2013, 01:33 PM
|
 |
Contributing User
|
|
Join Date: Jan 2003
Location: USA
|
|
Quote: | I am trying allocate the size dynamically based on the amount of the emails generated. |
Where? In the original listing I didn't see any new or delete nor did I see any STL containers being used.
Still, running an infinite loop that keeps eating up resources will inevitably result in a crash. How big is each email? When you have 5000 of them, how much heap have you used up? How much heap are you given in the first place (that information might be available in the Project Properties)? Remember, you have finite, limited resources to work with.
|

February 24th, 2013, 01:41 PM
|
|
Registered User
|
|
Join Date: Feb 2013
Posts: 8
Time spent in forums: 2 h 32 m 42 sec
Reputation Power: 0
|
|
Here is the current code I am compiling I hope this helps...
Do I have to use STL to assign dynamic size to the loop? I am not using STL here.
Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
#define MAX 1000000
string emails[MAX];
int main()
{
//
// When debugging, I often print something before any code in the program:
// just to make sure it has started.
//
cout << "MAX = " << MAX << endl;
int e, f, ff, gf, i, j, k, l, m, n, num;
string STRING1;
string STRING2;
string STRING3;
string adds[5] = {"@hotmail.com", "@yahoo.com", "@gmail.com", "@msn.com", "@excite.com"};
char Init[1000];
string ffstName[1000];
string gfstName[1000];
string lstNames[1000];
string InitL[1000];
string emailsL[5000];
string emailsI[5000];
ifstream infile1;
ifstream infile2;
ifstream infile3;
infile1.open ("fmlsFName.txt");
infile2.open ("guysFName.txt");
infile3.open ("LstName.txt");
cout << "Enter the number of emails to generate in millions: " ;
cin >> num;
// I always show the value that the program obtained
// from the user.
//
cout << "You entered num = " << num << endl;
int cnt = num * 1000; // Not used???
int maxCnt = MAX/(cnt); // Not used???
int cntEAd = 1;
cout << "Loop for max of 999 ffstName strings" << endl;
while(getline(infile1, STRING1))
{
for(ff = 0; ff < 999; ++ff)
{
infile1 >> ffstName[ff];
}
cout << "Going back for another line." << endl;
}
cout << "Loop for max of 999 gfstName strings " << endl;
while(getline(infile2, STRING2))
{
for(gf = 0; gf < 999; ++gf)
{
infile2 >> gfstName[gf];
}
cout << "Going back for another line." << endl;
}
cout << "Loop for max of 999 lstName strings" <<endl;
while(getline(infile3, STRING3))
{
for(l = 0; l < 999; ++l) {
infile3 >> lstNames[l];
for(n = 0; n < lstNames[ l ].size(); ++n)
InitL[n] = lstNames[n][0];
for(i = 0; i < 5; i++) {
emailsL[l] = lstNames[l] + adds[i];
emailsI[n] = Init[n] + adds[i];
}
}
cout << "Going back for another line." << endl;
}
cout << "Loop for assigning " << MAX << " emailsL strings to emails" << endl;
int size=sizeof emailsL/sizeof(int); //total size of array/size of array data type
cout<<size;
while(cntEAd <= size - 1)
{
for(e = 0; e < size; e++)
{cout << "The list of email is " << emailsL[e] ;
cout << " it is inserted in to array [" << e << "]." <<endl;
cout << "The size of generated emails is: " << size <<endl;
emails[e] = emailsL[e];
cntEAd++;
}
cout << "The number of emails generated are: " << cntEAd <<endl;
}
// Rest of the code
infile1.close();
infile2.close();
infile3.close();
return 0;
}
Quote: | Originally Posted by dwise1_aol Where? In the original listing I didn't see any new or delete nor did I see any STL containers being used.
Still, running an infinite loop that keeps eating up resources will inevitably result in a crash. How big is each email? When you have 5000 of them, how much heap have you used up? How much heap are you given in the first place (that information might be available in the Project Properties)? Remember, you have finite, limited resources to work with. |
|

February 24th, 2013, 02:45 PM
|
 |
Contributing User
|
|
Join Date: Jan 2003
Location: USA
|
|
|
Hey, we don't know just what you're trying to do here. E-Oreo tried to ask you, but you just blew him off so I'm sure that he's given up on you.
Now, let me try this for a third time. You have an infinite loop that keeps using up limited resources. This can only end in your program crashing. What do you intend to do about that?
Yet again, how big is each email? When you have 5000 of them, how much memory has that used up? Dynamic allocation is done through the heap. How much heap are you given to play with?
You've got several huge arrays and who knows what they're doing? And this doesn't make any sense:
int size=sizeof emailsL/sizeof(int);
emailsL is an array of string whose size you already know, 5000. But you are dividing that by the sizeof int. What is that supposed to mean? I've never looked at the sizeof string, but I believe it should be much larger than that of an int, so size will be much larger than 5000.
Work it out on paper how much memory you're using. You appear to be using up your resources, so you need to get a handle on that.
I'm off to salsa now and then tonight is the Second Doctor.
|

February 24th, 2013, 04:27 PM
|
|
Registered User
|
|
Join Date: Feb 2013
Posts: 8
Time spent in forums: 2 h 32 m 42 sec
Reputation Power: 0
|
|
|
OH My, I didn't blow anybody off that would be the last thing I will do. I am probably not getting the lingo here. I have three arrays that have 1000 each where I get the first and last names.
I am trying figure out how to change that infinite loop to stop at some point. I am not sure how though.
I am trying generate as many email addresses as i can that are unique not duplicated and that's why I have assigned different arrays for each of them first and trying merge them later on.
How do I check how much heap I have to play with? This is something I wrote from scratch and the professor wants us to generate millions of email addresses with in a few seconds or minutes.
The emails could be from 1 million to 500 million based on the user inputs.
This right here "int size=sizeof emailsL/sizeof(int);" something I found on tutorial how to find out the size of the array based on the amount generated each time.
How do I calculate how much memory I am using? Earlier when I run it emailsL generated around 4000 email addresses but the loop crashed after running 5000 times.
Hope this helps, I don't think I understood the questions very well. I haven't done programming in a very long time so just now getting back at it.
|

February 25th, 2013, 12:17 AM
|
 |
Contributing User
|
|
Join Date: Jan 2003
Location: USA
|
|
There's a property page which allows some heap settings to be made, though I haven't played with it. I do know that in the header of a .exe file, there's a field for the amount of heap that the program wants allocated to it and the minimum that it will still accept, so it only makes sense that there must be some options you can set for that.
I think that "int size=sizeof emailsL/sizeof(int);" isn't quite right, because I believe the array it was intended for in the tutorial was an int array, whereas you're dealing instead with a an array of string, so you should have divided by sizeof(string) instead. Ironically, it just so happens that in my MinGW g++ compiler, string and int are both the same size, 4 bytes long. That makes me suspect that strings are treated as a pointer to the string object, but I'd have to research that more. At any rate, because you had declared the string array to be 5000 long, you already knew the array's size.
OK, how big are you data structures? How much memory are you using? In an array of 1 million strings, that array itself would be 4 million bytes. That's in RAM, also called static storage, and not in heap, but each element of that array points to the actual string which I believe would be allocated dynamically in the heap. What's the average length of one of those email address strings? More than ten characters long, maybe as much as twenty easily. A million of those would mean that you'd be using 10 to 20 million bytes of heap. I rather doubt that that much heap gets allocated. You saw your program crash at about 5000 emails, meaning that the main array's demand on the heap would have been about 50,000 to 100,000 bytes, though the three local arrays of 5000 strings each would have added an extra load of 150,000 to 300,000 bytes. That's a lot. And, of course, if you go for 500 million the load will only increase 500 fold.
MicroSoft Developers' Network (MSDN) maintains an on-line library of function documentation and articles, such as Managing Heap Memory, which appears to say that by default we're given 1MB of heap.
Would you be able to work with smaller arrays by off-loading some of the results to a disk file?
|

February 25th, 2013, 01:20 AM
|
|
Registered User
|
|
Join Date: Feb 2013
Posts: 8
Time spent in forums: 2 h 32 m 42 sec
Reputation Power: 0
|
|
|
Thank you that was very good explanation and its pretty clear.
I will try to play with setting up the heap when i get a chance.
For the question if I could be able to load off some of the emails generated, yes I could do that. Actually the homework states to save all the generated file to the file user requested. So, that was my last goal once I figure how to do this part.
I will play with small scale just to debug my program then once i get this sorted I will try to load it to the file as it generates bigger data.
Regards,
-aK>
|

March 2nd, 2013, 03:31 AM
|
|
Registered User
|
|
Join Date: Feb 2013
Posts: 8
Time spent in forums: 2 h 32 m 42 sec
Reputation Power: 0
|
|
First and foremost I want to say Thank you very much for all the assistance you guys provided me. I am sorry it took me little longer to respond due to my hectic schedule with school and work. I submitted the homework as a working condition even though not as good as I want it to be.
I have made my program small enough to read a few lines as well as created a file with small amount of names. Then I change a few things to make my array dynamic then played around with numbers I want to produce.
The only problem if I could I would like to fix right now is the amount of time it takes to execute. My last updated program is below.
Best Regards,
-aK>
Code:
/*
This was written in c++ and it could be run in any visual studio environment.
It will generate unique email addresses but not random.
*/
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
using namespace std;
const int siz = 10000000; //10 million
int main()
{
int e, f, ff, gf, i, j, k, l, m, n, num;
string StrngF;
string StrngL;
//email addresses to assign u could add more to have a lot of uniqueness
string adds[5] = {"@hotmail.com", "@yahoo.com", "@gmail.com", "@msn.com", "@excite.com"};
char * Init = new char[siz];
Init[siz-1] = 9999; //first initials may b used as a middle initials later on
string * fstNames = new string[siz];
fstNames[siz-1] = 1999; //list of first names
string * lstNames = new string[siz];
lstNames[siz-1] = 9999; //list of last names
string * InitL = new string[siz];
InitL[siz-1] = 9999; //initials taken from last names
string * emails = new string[siz];
emails[siz-1] = 9999; //email addresses created by last name only
//
// Give it a name so that you can print out a message.
// You might want to change the name some day, so
// define it in one place.
//
ifstream infilef; //females first name file
ifstream infilel; //last name file
ofstream outdata; //outdata is like cin
//open the files to be used
infilef.open ("frstNames.txt");
infilel.open ("LstName.txt");
//
// Give it a name so that you can print out a message.
// You might want to change the name some day, so
// define it in one place.
//
const char *inFname = "frstNames.txt";
const char *inLname = "LstNames.txt";
outdata.open("example2.txt"); //opens the file
//
// Test to see if it opened.
//
if (!infilef)
{
cout << "There was a problem opening "
<< inFname
<< " for reading." <<endl;
return 0;
}
//
// Make the program tell you what it is working on.
//
cout << "Opened file "
<< inFname
<< " for reading."
<< endl;
if (!infilel)
{
cout << "There was a problem opening "
<< inLname
<< " for reading." <<endl;
return 0;
}
//
// Make the program tell you what it is working on.
//
cout << "Opened file "
<< inLname
<< " for reading."
<< endl;
while(getline(infilef, StrngF))
{
for(f = 0; f < 1999; ++f)
{
infilef >> fstNames[f]; //save first names to the array for later use
}
}
while(getline(infilel, StrngL))
{
for(l = 0; l < 9999; ++l)
{
infilel >> lstNames[l]; //save last names to the array
InitL[l] = lstNames[l][0];
}
}
cout <<"Enter the number of email addresses you want to create: (IN MILLIONS) " ;
cin >> n;
n = n*1000000;
for(e = 0; e < n; ++e) //f for first name count ex: fstName[0] = ab
{
for(l = 0; l < n; ++l)
{
for(i = 0; i < 5; ++i) //i for email prvdrs count ex: abcathotmaildotcom
{
if(n <= 0)
break;
outdata << fstNames[e] + lstNames[l] + adds[i] << endl;
n--;
if(n <= 0)
break;
outdata << lstNames[l] + fstNames[e] + adds[i] << endl;
n--;
if(n <= 0)
break;
outdata << lstNames[l] + InitL[l] +"_"+fstNames[e] + adds[i] <<endl;
n--;
}
}//system("pause");
}
infilef.close();
infilel.close();
outdata.close();
delete [] Init;
delete [] fstNames;
delete [] lstNames;
delete [] InitL;
delete [] emails;
return 0;
}
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|