Board index » delphi » Memory management limitations Win x Linux
Clément Doss
![]() Delphi Developer |
Memory management limitations Win x Linux2007-06-07 03:30:33 AM delphi47 Hi, A friend of mine wrote a C++ program, and he has a problem. This program depends on an algorithm he wrote that will allocate a lot of memory in order to do some heavy calculations and produce some numbers. He is using a linux and a native c++ compiler. The problem lies here: const int N1=3; const int Ip=6500; const int I=6500; const int min_branch_size=1; int main(void) { const int max_branch_size=max(min_branch_size,I); double **sample, **sample_tk; sample=new double* [Ip*max_branch_size]; <---- Here sample[0]=new double[(Ip*max_branch_size)*(N1)]; <---- Here .... } The fact is he need "a little more info" for his algorithm to be more effective, and when he sets Ip=12000 and I=12000 (would be close to ideal), there's a bad_alloc error. From what I can see, there's a 12000 * 12000 * 8 = 1.152.000.000 bytes and 12000 * 12000 * 8 * 3 = 3.456.000.000. What's 4.5Gb of ram of data for a 500 lines C++ program? :-) He asked me to convert the program to delphi and make some tests, but with the figures above, I really couldn't give him any hope. And as expected, I had a similar problem. I downloaded turbo c++ explorer, and tried to compiled it. I ran the program but the error is still there. With some nice hints by the way!! (Windows XP 2.5 Gb Ram) As the memory grows, shouldn't some virtual memory kick in under windows? and under linux? Anyway I wouldn't expect him to have such a problem (memory limitation) under linux. I told him to change the "double" (64-bit) for "float" (32-bit) to see if that affects the calculations. He is checking this write now. Ok this would cut in half the memory consumption. Is there any setting in the environment (or command line option, switch, flag) he can make in order to compile and run such a memory consuming beast? Of course he wouldn't like to make any changes in the code. But if changes should be made, would it be possible to still use memory (instead of writing to disk as there are lots of calculations, there will be an extra problem with the time the algorithm will take to give an answer.) TIA, Clément |