Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

c_allocator.h

Go to the documentation of this file.
00001 /* -*- mode: C++; c-file-style: "stroustrup"; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
00002 /*********************************************************************
00003  *
00004  * Filename : c_allocator.h (base)
00005  *
00006  * This file is a part of the UPPAAL toolkit.
00007  * Copyright (c) 1995 - 2003, Uppsala University and Aalborg University.
00008  * All right reserved.
00009  *
00010  * $Id: c_allocator.h,v 1.2 2004/06/14 07:36:53 adavid Exp $
00011  *
00012  *********************************************************************/
00013 
00014 #ifndef INCLUDE_BASE_C_ALLOCATOR_H
00015 #define INCLUDE_BASE_C_ALLOCATOR_H
00016 
00017 #include <stddef.h>
00018 #include "base/inttypes.h"
00019 
00020 /**
00021  * @file
00022  * Definition of the allocator function type
00023  * and declaration of a default function based
00024  * on malloc.
00025  * In different places where C libraries need
00026  * memory management, we want to stay independent
00027  * from particular needs. A generic allocator function
00028  * is declared for this purpose.
00029  */
00030 
00031 #ifdef __cplusplus
00032 extern "C" {
00033 #endif
00034 
00035 
00036 /** Allocator function.
00037  * @param intSize: size to allocate in ints
00038  * @param data: custom data for the allocator
00039  * (ignored for malloc, for example, important
00040  *  for a custom allocator)
00041  * @return int32_t[intSize]
00042  */
00043 typedef int32_t* (*allocator_f)(size_t intSize, void *data);
00044 
00045 
00046 /** Deallocator function.
00047  * @param mem: memory to deallocate
00048  * @param intSize: size to deallocate in ints
00049  * @param data: custom data for the allocator
00050  * @pre intSize must correspond to the allocated
00051  * size, mem != NULL.
00052  */
00053 typedef void (*deallocator_f)(void *mem, size_t intSize, void *data);
00054 
00055 
00056 /** Allocator = allocator function + custom data.
00057  */
00058 typedef struct
00059 {
00060     void *allocData;
00061     allocator_f allocFunction;
00062     deallocator_f deallocFunction;
00063 } allocator_t;
00064 
00065 
00066 /** Default allocator function based on malloc.
00067  * @param intSize: size to allocate in ints
00068  * @param unused: not used, only to comply with allocator_f
00069  * @return int32_t[intSize] allocated by malloc
00070  */
00071 int32_t* base_malloc(size_t intSize, void *unused);
00072 
00073 
00074 /** Default deallocator function based on free.
00075  * @param mem: memory to deallocate
00076  * @param unused1,unused2: unused parameters, only to comply
00077  * with deallocator_f.
00078  */
00079 void base_free(void *mem, size_t unused1, void *unused2);
00080  
00081 
00082 /** Default allocator type based on malloc.
00083  */
00084 extern allocator_t base_mallocator;
00085 
00086 #ifdef __cplusplus
00087 }
00088 #endif
00089 
00090 #endif /* INCLUDE_BASE_C_ALLOCATOR_H */

Generated on Fri Jun 30 00:02:30 2006 for Module base by  doxygen 1.4.2