Memory Management in Maple 16 - Maple Programming Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : System : Information : Updates : Maple 16 : updates/Maple16/memorymanagement

Memory Management in Maple 16

Automatic memory management alleviates a programmer from the low-level details of allocating and deallocating storage space for the results of their computation. Although automatic memory management comes with a cost, relieving programmers from this low-level task enables them to concentrate on developing correct and efficient high-level algorithms to solve their problems and, in general, more than covers the overhead of automatic memory management.

Significant improvements have been made to both the memory allocator and garbage collector that together comprise Maple's memory management system.  The modernization of the memory management system positions Maple to effectively use the resources available on not only the machines of today but also those of tomorrow.  For example, the advances in CPU performance will continue to be driven by the increase in the number of  cores per chip.  Matching this trend, the advances to both the memory allocator and garbage collector are primarily centered around simultaneously handling the memory demands of multiple threads.  Furthermore, improvements enabling Maple to more effectively use the larger amounts of memory available on 64-bit architectures will continue to be seen.

The most significant benefit derived from the modernized memory management system is Maple's parallel performance.  Previously, the interplay between threads would artificially retain garbage for long periods of time.  Improvements to the garbage collector allow it to now examine the memory usage of each specific Maple thread in the system and identify garbage at a much finer granularity than before.  This translates into a reduction in the amount of time and memory required to complete many computations.  These improvements can be seen in the Mandelbrot set example used to demonstrate the task programming model (see examples,Task).  On a quad-core processor the amount of memory allocated decreased by almost 70% while performance improved by 42%.

Previously, Maple continuously requested chunks of memory from the underlying operating system's memory allocator as more memory was required.  These chunks were not necessarily contiguous in memory and therefore were rarely coalesced into larger chunks that could possibly satisfy an even larger memory allocation (instead another request would be sent to the operating system).  Adopting the strategy taken by the runtime systems of many other programming languages, Maple now manages a large contiguous block of virtual memory and expands into it on demand as needed.   

Although users are still able to trigger a garbage collection by calling gc(), its use is discouraged.  The improvements to Maple's memory management system have made it heavily demand driven and directly calling gc() can increase the amount of work that the system performs.

Garbage collection while executing external routines has historically been troublesome.  Maple is now capable of garbage collecting in many places where it was previously unable to.  This can result in improved memory usage and performance.  Consider the following linear algebra example:

restart:withLinearAlgebra:Digits20: ARandomMatrix300,outputoptions=datatype=float:BRandomVector300,outputoptions=datatype=float:try  X  CodeTools:-Usage LinearSolveA,B :catch:end try:

The ability to garbage collect almost anywhere helped this example to speed up by close to 40%.