MapleAlloc - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


MapleAlloc

allocate memory in external code

MapleDispose

free memory in external code

 

Calling Sequence

Parameters

Description

Examples

Calling Sequence

MapleAlloc(kv, n)

MapleDispose(kv, s)

Parameters

kv

-

kernel handle of type MKernelVector

n

-

number of bytes to allocate

s

-

type ALGEB object

Description

• 

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.

Examples

    #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.

withExternalCalling&colon;

dllExternalLibraryNameHelpExamples&colon;

fcatDefineExternalMyConcat&comma;dll&colon;

lfcatfoo&comma;1.1

lfoo1.100000

(1)

assignevall&comma;1&comma;17

l

17

(2)

Note: The name returned is local (it does not match the global name).

`foo1.100000`

foo1.100000

(3)

dismantlehexevall&comma;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