David Mebane writes: > > Upon receiving some advice, I have attached here the entire piece of code I'm > trying to run. It's a Newton solver; LSMbdnew is the generic solver, and > bulkfunc contains the function (f) and Jacobian (jac). The whole thing may look > a little ugly to the experienced programmers on this list -- sorry. > > Anyway, this will compile and run, but it won't do what it's supposed to. I > found out with gdb that the reason for this is that the function > LSMbdnew::norm(double *vec1, long num) is not executing the add/assign properly. > For some reason, it sets the collecting variable _ret_ to zero after one or two > iterations. Why? I am stumped. Running valgrind reveals that you're using delete where you should be using delete[]. Once that is fixed, the program seems reasonable enough. I get: 1.07504e-09 0.391644 0.0400001 0.189609 0.0519544 0.00205729 regardless of whether += is used or not. But this isn't a testcase without sample results. What results do you expect? Andrew. ==8099== Memcheck, a memory error detector. ==8099== Copyright (C) 2002-2005, and GNU GPL'd, by Julian Seward et al. ==8099== Using LibVEX rev 1471, a library for dynamic binary translation. ==8099== Copyright (C) 2004-2005, and GNU GPL'd, by OpenWorks LLP. ==8099== Using valgrind-3.1.0, a dynamic binary instrumentation framework. ==8099== Copyright (C) 2000-2005, and GNU GPL'd, by Julian Seward et al. ==8099== For more details, rerun with: -v ==8099== ==8099== Mismatched free() / delete / delete [] ==8099== at 0x4904F6F: operator delete(void*) (vg_replace_malloc.c:246) ==8099== by 0x401E1C: LSMbdnew::iterate() (LSMbdnew.h:94) ==8099== by 0x401FCB: main (testnew.cpp:29) ==8099== Address 0x4A201B0 is 0 bytes inside a block of size 48 alloc'd ==8099== at 0x4905A0A: operator new[](unsigned long) (vg_replace_malloc.c:201) ==8099== by 0x401C60: LSMbdnew::iterate() (LSMbdnew.h:74) ==8099== by 0x401FCB: main (testnew.cpp:29) ==8099== ==8099== Mismatched free() / delete / delete [] ==8099== at 0x4904F6F: operator delete(void*) (vg_replace_malloc.c:246) ==8099== by 0x401E25: LSMbdnew::iterate() (LSMbdnew.h:95) ==8099== by 0x401FCB: main (testnew.cpp:29) ==8099== Address 0x4A200F0 is 0 bytes inside a block of size 48 alloc'd ==8099== at 0x4905A0A: operator new[](unsigned long) (vg_replace_malloc.c:201) ==8099== by 0x401C30: LSMbdnew::iterate() (LSMbdnew.h:72) ==8099== by 0x401FCB: main (testnew.cpp:29) ==8099== ==8099== Mismatched free() / delete / delete [] ==8099== at 0x4904F6F: operator delete(void*) (vg_replace_malloc.c:246) ==8099== by 0x401E2E: LSMbdnew::iterate() (LSMbdnew.h:96) ==8099== by 0x401FCB: main (testnew.cpp:29) ==8099== Address 0x4A20150 is 0 bytes inside a block of size 48 alloc'd ==8099== at 0x4905A0A: operator new[](unsigned long) (vg_replace_malloc.c:201) ==8099== by 0x401C48: LSMbdnew::iterate() (LSMbdnew.h:73) ==8099== by 0x401FCB: main (testnew.cpp:29) ==8099== ==8099== Mismatched free() / delete / delete [] ==8099== at 0x4904F6F: operator delete(void*) (vg_replace_malloc.c:246) ==8099== by 0x401E37: LSMbdnew::iterate() (LSMbdnew.h:97) ==8099== by 0x401FCB: main (testnew.cpp:29) ==8099== Address 0x4A20090 is 0 bytes inside a block of size 48 alloc'd ==8099== at 0x4905A0A: operator new[](unsigned long) (vg_replace_malloc.c:201) ==8099== by 0x401BDB: LSMbdnew::iterate() (LSMbdnew.h:67) ==8099== by 0x401FCB: main (testnew.cpp:29) ==8099== ==8099== Mismatched free() / delete / delete [] ==8099== at 0x4904F6F: operator delete(void*) (vg_replace_malloc.c:246) ==8099== by 0x402019: main (testnew.cpp:34) ==8099== Address 0x4A20030 is 0 bytes inside a block of size 48 alloc'd ==8099== at 0x4905A0A: operator new[](unsigned long) (vg_replace_malloc.c:201) ==8099== by 0x401EA7: main (testnew.cpp:14) ==8099== ==8099== ERROR SUMMARY: 5 errors from 5 contexts (suppressed: 4 from 1) ==8099== malloc/free: in use at exit: 0 bytes in 0 blocks. ==8099== malloc/free: 5 allocs, 5 frees, 240 bytes allocated. ==8099== For counts of detected errors, rerun with: -v ==8099== No malloc'd blocks -- no leaks are possible.