455,128 Members | 1,206 Online Need help? Post your question and get tips & solutions from a community of 455,128 IT Pros & Developers. It's quick & easy.

# Question about Memory Allocation and the SHORT INT in STL

 P: n/a I am writting an algorithm that generates very large tables in dynamic memory on a linux system. These 2 tables are of the order of (30,000 x 30,000). They are being generated by the following code: std::vector table; for(i=0; i < 30000; i++) { row = new short int; table.push_back( row ); } The algorithm crashes before creating the table. There is also no feedback from the command line as to why the system crashes. I need to determine two things: 1) What is the EXACT error that is produced by the system. Is there a way to create an error log file that lists all errors generated by the system at the time of the crash. Maybe, for example, it could show that mmap failed to allocate enough memory, etc. 2) I need a way to predict the amount of memory that will be used by the system. What size, in bits, would this table be? Is a SHORT INT 16bits when used in the vector class? I would think that size = (30000)(30000)(16) Thanks Jul 23 '05 #1
3 Replies

 P: n/a PhoneJack wrote: I am writting an algorithm that generates very large tables in dynamic memory on a linux system. These 2 tables are of the order of (30,000 x 30,000). They are being generated by the following code: std::vector table; for(i=0; i < 30000; i++) { row = new short int; table.push_back( row ); } The algorithm crashes before creating the table. There is also no feedback from the command line as to why the system crashes. I need to determine two things: 1) What is the EXACT error that is produced by the system. Is there a way to create an error log file that lists all errors generated by the system at the time of the crash. Maybe, for example, it could show that mmap failed to allocate enough memory, etc. 2) I need a way to predict the amount of memory that will be used by the system. What size, in bits, would this table be? Is a SHORT INT 16bits when used in the vector class? I would think that size = (30000)(30000)(16) Thanks I suspect you're running out of memory, and new is throwing std::bad_alloc, which you don't appear to catch. I would try the following: std::vector table; int i; try { for (i = 0 ; i < 30000; ++i) table.push_back(new short int); } catch (std::exception& e) { std::cout << "EXCEPTION: " << e.what << std::endl; // drop dead here in some clean manner. } Jul 23 '05 #2

 P: n/a PhoneJack wrote: I am writting an algorithm that generates very large tables in dynamic memory on a linux system. These 2 tables are of the order of (30,000 x 30,000). They are being generated by the following code: std::vector table; for(i=0; i < 30000; i++) { row = new short int; table.push_back( row ); } The algorithm crashes before creating the table. There is nothing in the code to suggest a problem _except_ if you're running out of memory. Consider that 30k x 30k x sizeof(short) is only 1800 Mbytes (1.8 Gigabytes). And how much do you have virtual memory in your process to play with? There is also no feedback from the command line as to why the system crashes. Surround your loop with int i; try { <... your loop here ...> } catch (std::bad_alloc const& e) { cout << "ran out of memory on " << i << "th loop\n"; } I need to determine two things: 1) What is the EXACT error that is produced by the system. Is there a way to create an error log file that lists all errors generated by the system at the time of the crash. Maybe, for example, it could show that mmap failed to allocate enough memory, etc. Catch proper exceptions. 2) I need a way to predict the amount of memory that will be used by the system. What size, in bits, would this table be? Is a SHORT INT 16bits when used in the vector class? I would think that size = (30000)(30000)(16) Yes. Got a calculator? V Jul 23 '05 #3

 P: n/a > I am writting an algorithm that generates very large tables in dynamic memory on a linux system. These 2 tables are of the order of (30,000 x 30,000). They are being generated by the following code: std::vector table; for(i=0; i < 30000; i++) { row = new short int; table.push_back( row ); } The algorithm crashes before creating the table. If you run out of memory, new throws an exception. Try to catch it and to print a message to see if that's the case. There is also no feedback from the command line as to why the system crashes. I need to determine two things: 1) What is the EXACT error that is produced by the system. Is there a way to create an error log file that lists all errors generated by the system at the time of the crash. Maybe, for example, it could show that mmap failed to allocate enough memory, etc. Not in standard C++. Ask in a newsgroup supporting your compiler or system 2) I need a way to predict the amount of memory that will be used by the system. What size, in bits, would this table be? Is a SHORT INT 16bits when used in the vector class? Depends on the system. Try to do std::cout << sizeof(short int); I would think that size = (30000)(30000)(16) If on your system a short int is 16 bits, that would give you the number of bits you allocated. You probably want it in bytes. sizeof(short int) returns the number of bytes: (30000)*(30000)*(sizeof(short int)). Jonathan Jul 23 '05 #4

### This discussion thread is closed

Replies have been disabled for this discussion. 