MapleAlloc
allocate memory in external code
MapleDispose
free memory in external code
Calling Sequence
Parameters
Description
Examples
MapleAlloc(kv, n)
MapleDispose(kv, s)
kv
-
kernel handle of type MKernelVector
n
number of bytes to allocate
s
type ALGEB object
These functions can be used in external code with OpenMaple or define_external.
MapleAlloc allocates n bytes of memory and returns a pointer to it. MapleDispose frees this memory so it can be reused for other purposes.
MapleAlloc is used to access temporary memory that will be cleaned up by the Maple garbage collector. The memory returned by MapleAlloc cannot be protected from gc. To allocate memory that persists, use standard non-Maple memory allocation methods in combination with a MaplePointer.
MapleDispose releases the memory allocated to the structure s. It must be used only on data structures created using MapleAlloc.
#include <stdio.h>
#include "maplec.h"
ALGEB M_DECL MyConcat( MKernelVector kv, ALGEB *args )
{
char *name, *tmp;
FLOAT64 f;
size_t len;
if( MapleNumArgs(kv,(ALGEB)args) != 2 ) {
MapleRaiseError(kv,"two arguments expected");
return( NULL );
}
name = MapleToString(kv,args[1]);
f = MapleToFloat64(kv,args[2]);
len = strlen(name);
tmp = (char*)MapleAlloc(kv,(len+30)*sizeof(char));
sprintf(tmp,"%s%f",name,f);
return( ToMapleName(kv,tmp,FALSE) );
Execute the external function from Maple.
with⁡ExternalCalling:
dll≔ExternalLibraryName⁡HelpExamples:
fcat≔DefineExternal⁡MyConcat,dll:
l≔fcat⁡foo,1.1
l≔foo1.100000
assign⁡eval⁡l,1,17
l
17
Note: The name returned is local (it does not match the global name).
`foo1.100000`
foo1.100000
dismantlehex⁡eval⁡l,1
NAME(7FDDBCB95230,5): `foo1.100000`
dismantlehex⁡`foo1.100000`
NAME(7FDDB4EEA938,5): `foo1.100000`
See Also
CustomWrapper
define_external
dismantle
gc
OpenMaple
OpenMaple/C/API
OpenMaple/C/Examples
Download Help Document