#include "memory.h"

This page has information from files memory.h and memory.c.

Contents


Public Routines in File memory.c

Index

megs_mallocedset_max_megstp_calloc
set_malloc_megstp_alloc

Details


int megs_malloced(void);
This routine returns the number of kilobytes that tp_alloc() has obtained from the operating system by malloc();
void set_malloc_megs(int megs);
This routine changes the size of the blocks obtained from malloc() by tp_alloc(). The argument is in megabytes. The default value is DEFAULT_MALLOC_MEGS.
void set_max_megs(int megs);
This routine changes the limit on the amount of memory obtained from malloc() by tp_alloc(). The argument is in megabytes. The default value is DEFAULT_MAX_MEGS.
void *tp_alloc(size_t n);
This routine allocates and returns a block of at least n bytes of memory, aligned so that it can be used for any kind of data. (The size of the block returned is a multiple of the size of a pointer.) The way it works is that a large block is obtained from malloc(), and this routine gives out pieces until it has to get more from malloc(), and so on.

If the operating system runs out of memory, or the amount requested is too great, or Max_megs is exceeded, the whole process just dies.


void *tp_calloc(size_t n);
This is just like tp_alloc(), except the memory is initialized to 0.

Public Definitions in File memory.h

#define DEFAULT_MAX_MEGS     96  /* Change with set_max_megs(). */
#define DEFAULT_MALLOC_MEGS   1  /* Change with set_malloc_megs(). */


Introduction

If you need a small chunks of memory to build data structures, this is where to come. We my_malloc() big blocks of memory, then break it up and give it out as needed.

Unlike malloc(), the memory obtained by tp_alloc() cannot be freed at this level of abstraction or to the operating system. Instead, it is assumed that the caller is some kind of get_node() routine, which, along with the corresponding free_node() routine, manages a list of available nodes.


These activities are projects of the Mathematics and Computer Science Division of Argonne National Laboratory.