MapleAlloc - Maple Programming Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Programming : OpenMaple : C Application Programming Interface : Memory and Foreign Object Management : OpenMaple/C/MapleAlloc

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

l:=foo1.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)

dismantle&lsqb;hex&rsqb;evall&comma;1


NAME(100007F32CA4454D6,5): `foo1.100000`

dismantle&lsqb;hex&rsqb;`foo1.100000`


NAME(100007F32CA447A4E,5): `foo1.100000`

See Also

CustomWrapper

define_external

dismantle

gc

OpenMaple

OpenMaple/C/API

OpenMaple/C/Examples

 


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam