Chinaunix首页 | 论坛 | 博客
  • 博客访问: 41492
  • 博文数量: 7
  • 博客积分: 162
  • 博客等级: 入伍新兵
  • 技术积分: 80
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-20 06:47
文章分类
文章存档

2011年(7)

我的朋友

分类: 嵌入式

2011-02-14 14:57:27

Matlab 与 C# 混合编程中,如果使用 C# 提供的 Marshal.AllocHGlobal 和 Marshal.FreeHGlobal,则会出现如下的错误提示:
Abnormal termination at .\src\mem\alignment.cpp line 333:
The pointer passed to 'vector_check' is invalid
and does not appear to have come from any of the following routines:
  vector_malloc, vector_calloc, vector_realloc
  mxMalloc*, mxCalloc*, mxRealloc*
This suggests one of the following has happened:
  - the pointer has already been freed
  - the pointer came from an incompatible allocator (e.g. new, malloc, utMalloc)
  - the pointer didn't come from any allocator (e.g. the stack, uninitialized me
mory)
  - a memory corruption destroyed the pointer or its header
 
 
  错误原因在于第二点,内存分配器不兼容,改用  Matlab 提供的 mxMalloc 和 mxFree 就可以了,但是 C# 的复制函数 Marshal.Copy 仍然可用。
 
   Matlab 与 C# 混合编程中分配内存和释放内存都必须使用 Matlab 提供的函数 mxMalloc 和 mxFree。
 
 
代码根据 《 MATLAB C# Book》 改写,但是有些小问题,特此记录。
阅读(2272) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:刷新 Matlab 工具箱的 cache

给主人留下些什么吧!~~