My problem is that I have a class, which should take a long int called "size", and use it to dynamically create an array of structs. The following compiles, but I get a runtime error that says the following:
error "terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc Aborted
struct PageEntry
{
..some stuff in here
};
class PageTable {
public:
PageTable(); //Default PageTable constructor.
PageTable(long int size); //PageTable constructor takes arrival time and execution time as parameter
~PageTable(); //PageTable destructor.
PageEntry *pageArray;
};
PageTable::PageTable(long int size)
{
cout << "creating array of page entries" << endl;
pageArray = new PageEntry[size]; //error occurs here
cout << "done creating" << endl;
}
The error doesn't occur if I replace "size" with a number, ie. 10000. Any thoughts?