Fortunately, I found many useful answers here, reading other questions, but this time I am completely helpless, so I myself must ask the question:
I am trying to create a program that applies convolution to a series of data. For convolution kernels (= arrays of certain numbers) that have different lengths.
I implement this using float** and inserting values ββinto double-dereferenced variables. The number of arrays is fixed, the length of each array is missing, so the "subarrays" are allocated using new - in the CreateKernels function after if .
This function then returns float** along with another pointer associated as a structure with the main one.
Now the problem is: I looked at the dereferenced values ββof my kernel pointers using a debug clock. Everything worked fine, and all numbers were calculated after the CreateKernels (i.e., they CreateKernels memory from the main ). But after the next command in main my numbers are completely screwed up. If I try to use the data in the following code, I get segfault.
So, what is my current reasoning: Since I use new to create variables, they should be on the heap and should remain there until I free[] is the xmdash variable; in any case, they should not be limited to the CreateKernels area. Assigning pointers to the kernel structure and returning them may be strange for some of you, but it works. So, what really ruins my data is the next command after CreatKernels . Initializing int instead of creating fstream will not ruin my numbers. But why?
Is this a management error for my OS? Or is this a stupid programming error? I run Ubuntu 12.04-64bit and used both Code::Blocks and g++ to compile (all default settings), and both executables give me segfault.
I would really appreciate any hint or experience in this issue!
This is the corresponding code:
#include <string>