Maple Professional
Maple Academic
Maple Student Edition
Maple Personal Edition
Maple Player
Maple Player for iPad
MapleSim Professional
MapleSim Academic
Maple T.A. - Testing & Assessment
Maple T.A. MAA Placement Test Suite
Möbius - Online Courseware
Machine Design / Industrial Automation
Aerospace
Vehicle Engineering
Robotics
Power Industries
System Simulation and Analysis
Model development for HIL
Plant Modeling for Control Design
Robotics/Motion Control/Mechatronics
Other Application Areas
Mathematics Education
Engineering Education
High Schools & Two-Year Colleges
Testing & Assessment
Students
Financial Modeling
Operations Research
High Performance Computing
Physics
Live Webinars
Recorded Webinars
Upcoming Events
MaplePrimes
Maplesoft Blog
Maplesoft Membership
Maple Ambassador Program
MapleCloud
Technical Whitepapers
E-Mail Newsletters
Maple Books
Math Matters
Application Center
MapleSim Model Gallery
User Case Studies
Exploring Engineering Fundamentals
Teaching Concepts with Maple
Maplesoft Welcome Center
Teacher Resource Center
Student Help Center
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