Maple Professionel
Maple Académique
Maple Edition Étudiant
Maple Personal Edition
Maple Player
Maple Player for iPad
MapleSim Professionel
MapleSim Académique
Maple T.A. - Suite d'examens de classement
Maple T.A. MAA Placement Test Suite
Möbius - Didacticiels de mathématiques en ligne
Machine Design / Industrial Automation
Aéronautique
Ingénierie des véhicules
Robotics
Energie
System Simulation and Analysis
Model development for HIL
Modélisation du procédé pour la conception de systèmes de contrôle
Robotics/Motion Control/Mechatronics
Other Application Areas
Enseignement des mathématiques
Enseignement de l’ingénierie
Enseignement secondaire et supérieur (CPGE, BTS)
Tests et évaluations
Etudiants
Modélisation financière
Recherche opérationnelle
Calcul haute performance
Physique
Webinaires en direct
Webinaires enregistrés
Agenda des évènements
Forum MaplePrimes
Blog Maplesoft
Membres Maplesoft
Maple Ambassador Program
MapleCloud
Livres blancs techniques
Bulletin électronique
Livres Maple
Math Matters
Portail des applications
Galerie de modèles MapleSim
Cas d'Etudes Utilisateur
Exploring Engineering Fundamentals
Concepts d’enseignement avec Maple
Centre d’accueil utilisateur Maplesoft
Centre de ressources pour enseignants
Centre d’assistance aux étudiants
MapleGcProtect - prevent garbage collection on an object in external code
MapleGcAllow - allow garbage collection on an object in external code
MapleGcIsProtected - test if an object is protected from garbage collection in external code
MapleGcMark - mark an object contained in a MaplePointer during a garbage collection
Calling Sequence
MapleGcProtect(kv, s)
MapleGcAllow(kv, s)
MapleGcIsProtected(kv, s)
MapleGcMark(kv, s)
Parameters
kv
-
kernel handle of type MKernelVector
s
type ALGEB object
Description
These functions can be used in external code with OpenMaple or define_external.
MapleGcProtect prevents the object, s, from being collected by the Maple garbage collector. The memory pointed to by s is not freed until Maple exits, is restarted, or a call to MapleGcAllow is issued. Any Maple objects that must persist between external function invocations must be protected, or associated with a MaplePointer mark function. This includes any external global or static ALGEB variables that will be referred to in a later external call. Failure to protect such a persistent variable can lead to unexpected results if the Maple garbage collector disposes of it between function calls.
MapleGcAllow allows the Maple garbage collector to reclaim storage used by the object, s. This does not necessarily mean that the storage will be reclaimed. It just means that the object obeys the same rules applied to all other Maple objects -- that they can be collected whenever there is no longer anything actively referring to them. Be careful not to allow garbage collection on any object that was not protected by you, or was protected prior to when your code was to protect it.
MapleGcIsProtected returns TRUE if the given object is protected from garbage collection.
MapleGcMark is used in combination with the MaplePointer mark function callback supplied by MaplePointerSetMarkFunction. It must be called only by such a callback. It is recommended that you use a MaplePointer with a mark function instead of protecting and unprotecting objects.
Examples
#include "maplec.h"
ALGEB M_DECL MySaveLast( MKernelVector kv, ALGEB *args )
{
static ALGEB last = NULL;
static M_BOOL was_protected = FALSE;
ALGEB prev;
if( !last ) {
last = ToMapleNULL(kv);
was_protected = MapleGcIsProtected(kv,last);
MapleGcProtect(kv,last);
}
if( MapleNumArgs(kv,(ALGEB)args) > 0 ) {
if( !was_protected )
MapleGcAllow(kv,last);
prev = last;
last = args[1];
return( prev );
return( last );
Execute the external function from Maple.
See Also
CustomWrapper, define_external, gc, OpenMaple, OpenMaple/C/API, OpenMaple/C/Examples, OpenMaple/C/MaplePointer
Download Help Document