![]() |
|
#1
|
|||
|
|||
Dynamic allocation of matrixDear All,
Im experiencing some problems with the dynamic allocation of a matrix, in fact the problem is a little bit more complicated: I come to the details. I want to read matrices from several files and perform some statistical analysis on those data. So I created a list of files which should be red, and then for each of them I read the matrix, store in some way, and perform statistic. Now I have two problems: 1) Working on windows with MSVC I compile easily the cose and if I run it with only one file (without the free() command for the matrix) everything works well. The program instead crashes when it comes to freeing the matrix, so the problem should be somewhere there. 2) Under Linux (Ubuntu 9.10) with the same code I compile correctly but I cannot run the program because it crashes soon after it reads the matrix.Giving this error: *** glibc detected *** ./amatr.out: free(): invalid next size (normal): 0x0c6a29c8 *** ======= Backtrace: ========= /lib/tls/i686/cmov/libc.so.6[0xb77b3ff1] /lib/tls/i686/cmov/libc.so.6[0xb77b56f2] /lib/tls/i686/cmov/libc.so.6(cfree+0x6d)[0xb77b879d] /lib/tls/i686/cmov/libc.so.6(fclose+0x14a)[0xb77a450a] ./amatr.out[0x8048bd1] /lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xe6)[0xb775fb56] ./amatr.out[0x80487a1] ======= Memory map: ======== 08048000-0804a000 r-xp 00000000 08:06 392510 /home/uzzen/Laura/prova/amatr.out 0804a000-0804b000 r--p 00001000 08:06 392510 /home/uzzen/Laura/prova/amatr.out 0804b000-0804c000 rw-p 00002000 08:06 392510 /home/uzzen/Laura/prova/amatr.out 089e7000-0c6ab000 rw-p 00000000 00:00 0 [heap] b7600000-b7621000 rw-p 00000000 00:00 0 b7621000-b7700000 ---p 00000000 00:00 0 b771a000-b7736000 r-xp 00000000 08:05 567 /lib/libgcc_s.so.1 b7736000-b7737000 r--p 0001b000 08:05 567 /lib/libgcc_s.so.1 b7737000-b7738000 rw-p 0001c000 08:05 567 /lib/libgcc_s.so.1 b7747000-b7749000 rw-p 00000000 00:00 0 b7749000-b7887000 r-xp 00000000 08:05 262412 /lib/tls/i686/cmov/libc-2.10.1.so b7887000-b7889000 r--p 0013e000 08:05 262412 /lib/tls/i686/cmov/libc-2.10.1.so b7889000-b788a000 rw-p 00140000 08:05 262412 /lib/tls/i686/cmov/libc-2.10.1.so b788a000-b788d000 rw-p 00000000 00:00 0 b788d000-b78b1000 r-xp 00000000 08:05 262420 /lib/tls/i686/cmov/libm-2.10.1.so b78b1000-b78b2000 r--p 00023000 08:05 262420 /lib/tls/i686/cmov/libm-2.10.1.so b78b2000-b78b3000 rw-p 00024000 08:05 262420 /lib/tls/i686/cmov/libm-2.10.1.so b78be000-b78c4000 rw-p 00000000 00:00 0 b78c4000-b78c5000 r-xp 00000000 00:00 0 [vdso] b78c5000-b78e0000 r-xp 00000000 08:05 517 /lib/ld-2.10.1.so b78e0000-b78e1000 r--p 0001a000 08:05 517 /lib/ld-2.10.1.so b78e1000-b78e2000 rw-p 0001b000 08:05 517 /lib/ld-2.10.1.so bf848000-bf85d000 rw-p 00000000 00:00 0 [stack] I am working with matrices of about 2000 rows X 8000 columns. The cose is as follows: CPP / C++ / C Code:
Any help is appreciated. Thank you in advance. Fastest Last edited by LuciWiz : 05-Nov-2009 at 12:49.
Reason: Please insert your C code between [cpp] & [/cpp] tags
|
|||
|
#2
|
|||
|
|||
Re: Dynamic allocation of matrixAfter just glancing at the code, I noticed one thing that stood out to me: All of your loops referencing the matrices start with one and include the number of matrices. In C, arrays are zero-based, not one-based:
CPP / C++ / C Code:
|
|
#3
|
|||
|
|||
Re: Dynamic allocation of matrixThe problem is that you used tabs in your code. Try it with spaces instead.
Also , you should post a complete example. We can't even see how your data is declared! |
|
#4
|
|||
|
|||
Re: Dynamic allocation of matrixDear all,
as fakepoo suggested I tried to change to one based array to zero based array. Incredibly it works now: under Linux environment it runs until the end. Thank you also to Howard, even if I did not get exactly what he was meaning with Quote:
Regards Fastest |
|
#5
|
|||
|
|||
Re: Dynamic allocation of matrixI meant read about "using tabs in the code you post here" in the Guidelines
(I was kidding about tabs breaking your program (or was I)) |
Recent GIDBlog
Problems with the Navy (Chiefs) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Dynamic 2D Array / Matrix | TransformedBG | C++ Forum | 4 | 14-Jan-2007 12:03 |
| i need help in C++ PLZ | its_me | C++ Forum | 3 | 04-Dec-2006 22:51 |
| Help with OOP classes and Dynamic Allocation | noob2c++ | C++ Forum | 3 | 18-Sep-2006 18:41 |
| Dynamic memory allocation | cpit | C++ Forum | 1 | 15-Sep-2006 12:55 |
| Combining Vectors and References | Frankg | C++ Forum | 7 | 14-Jan-2006 07:17 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The