Malloc Replacements

This page describes possible malloc replacements to be used for memory management in SAGE which is not directly controlled by Python such as manual malloc/realloc calls, the GMP library etc..

Introduction

malloc

   1 sage: x = 3; y = 5
   2 
   3 sage: timeit _ = x + y
   4 100000 loops, best of 3: 7.37 mircoseconds per loop

PyMem_Malloc

The Python memory manager does keep track of some previous allocated, unused, but not yet freed blocks so it should be faster than malloc itself. It is currently used in GMP and Pyrex code in SAGE.

OMalloc

DLMalloc

default libCF Memory Manager

   1 sage: from sage.memory import * #only in my (malb) working copy
   2 
   3 # PyMem_Malloc
   4 sage: x = 5; y = 3
   5 sage: %timeit _ = x+y
   6 100000 loops, best of 3: 8.15 microseconds per loop
   7 
   8 # default libCF memory manager
   9 sage: memman_malloc()
  10 sage: %timeit _ = x+y
  11 100000 loops, best of 3: 7.36 microseconds per loop

libCF new Memory Manager

GivMM

   1 sage: from sage.memory import *
   2 sage: x = 5; y = 3
   3 
   4 # PyMem_Malloc
   5 sage: %timeit _ = x+y
   6 100000 loops, best of 3: 8.15 microseconds per loop
   7 
   8 # GivaroMM
   9 sage: givaro_malloc()
  10 sage: %timeit _ = x+y
  11 100000 loops, best of 3: 8.36 microseconds per loop