Friday, June 29, 2007

[Matlab][Debug]mxDestroyArray

Source

Matlab Help: Memory Management Compatibility Issues

Syndrome

The matlab engine properly opens and closes at the first time. But at the second attempt of starting matlab engine the error message pops up:
Forced Assertion: "Corrupted memory block found"

Cause

  • mxDestroyArray was called on a mxArray whose data was not assigned by matlab API
    mxArray *temp = mxCreateDoubleMatrix(1,5,mxREAL);
    double data[5] = {1,2,3,4,5};
    ...
    memcpy(mxGetPr(temp), data, 5*sizeof(double));
    ...
    mxDestroyArray(temp); // <-- INCORRECT. Do NOT call mxDestroyArray on temp

Solution

  • Do NOT call mxDestroyArray on such mxArray's

Thursday, June 14, 2007

C++ and C FAQ

Source

  • Comeau C++ and C FAQ
  • Embedded System Design
  • C++ FAQ LITE

    Description

    You can probably find answers to the fundamental questions about c++ programming.

    Memo

    • Constant objects can be declared with various types and user can access the address of the constant objects.
    • Enumeration Constants can only be integers and the address of enumeration constant is not available. But it also means that compilers won't generate codes for the ability to take the address, which becomes an advantage of using enumeration constants if users do not need the address of the constant.
    • When writing class template, the definition and the declaration should "be seen by compiler at the same time," which means one may 1. write both the declaration and the implementation in the same file (the .h file); 2. include the implementation file (.cpp) in the header file (.h), not include the header file in the implmenetation file. To explain this in one sentence: A class template is not a real class and the compiler will not see the functions of the class template with specified type.

  • Friday, June 08, 2007

    [LINUX] Bash Programming

    Source

    BASH Programming - Introduction HOW-TO by Mike G
    Advanced Bash-Scripting Guide by Mendel Cooper
    Bourne Shell Programming

    [LINUX] If The Script Does Not Run

    Check:

    • Is the script saved in Linux/Unix format (If saved in DOS format you may see "Command not found" error message). The command to remove the '\r' from DOS format is
      $ tr -d '\r' < DOS_file > UNIX_file
      The '<' is to input the DOS_file to command 'tr' and '>' is to output the file without '\r'. The commands including UNIX-to-DOS conversion can be found here
    • Is the script executable (if not you may see "Permission denied" error message