免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1469 | 回复: 0
打印 上一主题 下一主题

Matlab 和 C# 混合编程中的内存分配 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-02-14 14:57 |只看该作者 |倒序浏览
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》 改写,但是有些小问题,特此记录。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP