|
SOLUTIONS
|
MATHEMATICA MATHLINK C 関数
MLDeallocator
MathLink 形式の一つで,void * を引数として取り,メモリデアロケータを実行する void を返還形式として持つ関数に,関数ポインタを説明する.
詳細詳細
- メモリデアロケータ(解放)関数は,同じ位置に現れる要素をまとめることができるものでなくてはならない.
- MLDeallocator()はMathLink ヘッダファイルmathlink.hの中で宣言される.
例題例題すべて開くすべて閉じる
例 (1)例 (1)
#include <stdlib.h>
#include "mathlink.h"
/* AppAllocator implements a custom memory allocator */
void * AppAllocator(unsigned long size)
{
return malloc(size);
}
/* AppDeallocator implements a custom memory deallocator */
void AppDeallocator(void *m)
{
free(m);
}
int main(int argc, char **argv)
{
MLENV env;
MLINK link;
MLParameters p;
int error;
MLSetAllocParameter((char *)p, AppAllocator, AppDeallocator);
env = MLInitialize((char *)p);
if(env == (MLENV)0)
{ /* unable to initialize the MathLink environment */ }
link = MLOpenArgcArgv(env, argc, argv, &error);
if(link == (MLINK)0)
{ /* unable to create the link */ }
/* ... */
MLClose(link);
MLDeinitialize(env);
return 0;
}
Mathematica 9 is now available!
New to Mathematica?
Find your learning path »
Have a question?
Ask support »
