norrizuan wrote:
In void* ae_malloc(), the aligned_malloc was successfull (not NULL), but since mystate above is not NULL, this has cause the error (line 175 of aenv.c).
Lines 174-175 of aenv.c are
Code:
174: if( result==NULL && state!=NULL)
175: ae_break(state, ERR_OUT_OF_MEMORY, "ae_malloc(): out of memory");
if your aligned_malloc was successful, then it is not NULL, and you have no chance to jump to 175. No matter what value is stored in
state pointer. Either a) you made mistake when describing your situation, b) something is wrong with your compiler, or c) you have memory corruption problem which influences control flow of your program.
About ae_state structure. It is used by computational core for several purposes:
1. to store environment-specific information (endianness, IEEE special quantities, etc.)
2. for error handling (either C++ exception handling or setjmp/longjmp-based exception handling, depending on preprocessor definitions during compilation).
3. for automatic memory management - to release memory allocated for local variables during exception handling process. When ALGLIB exception is generated (either C++ exception or C longjmp-based one), all local arrays which were registered as automatic are freed. List of automatically managed arrays is stored in the state structure. This list has multilayered structure - automatic variables are organized into frames, one frame per one nested function call. When you exit function, only top frame is cleared. When exception is thrown, all frames are cleared.
This structure must be manually deallocated when it is no longer needed. You can register you variable as automatic (as you did by specifying ae_true in the ae_matrix_init() call), but it means that your matrix will be destroyed after deallocation of the ae_state structure.
P.S. It may sound overcomplicated, but it allows ALGLIB to use same code both for C++ and C versions without any significant changes.