Eneboo - Documentación para desarrolladores
src/hoard/src/heaplayers/addheap.h
Ir a la documentación de este archivo.
00001 /* -*- C++ -*- */
00002 
00003 #ifndef _ADDHEAP_H_
00004 #define _ADDHEAP_H_
00005 
00006 /*
00007 
00008   Heap Layers: An Extensible Memory Allocation Infrastructure
00009   
00010   Copyright (C) 2000-2003 by Emery Berger
00011   http://www.cs.umass.edu/~emery
00012   emery@cs.umass.edu
00013   
00014   This program is free software; you can redistribute it and/or modify
00015   it under the terms of the GNU General Public License as published by
00016   the Free Software Foundation; either version 2 of the License, or
00017   (at your option) any later version.
00018   
00019   This program is distributed in the hope that it will be useful,
00020   but WITHOUT ANY WARRANTY; without even the implied warranty of
00021   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022   GNU General Public License for more details.
00023   
00024   You should have received a copy of the GNU General Public License
00025   along with this program; if not, write to the Free Software
00026   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00027 
00028 */
00029 
00030 // Reserve space for a class in the head of every allocated object.
00031 
00032 #include <assert.h>
00033 
00034 namespace HL {
00035 
00036 template <class Add, class Super>
00037 class AddHeap : public Super {
00038 public:
00039   
00040   inline void * malloc (size_t sz) {
00041     void * ptr = Super::malloc (sz + align(sizeof(Add)));
00042     void * newPtr = (void *) align ((size_t) ((Add *) ptr + 1));
00043     return ptr;
00044   }
00045   
00046   inline void free (void * ptr) {
00047     void * origPtr = (void *) ((Add *) ptr - 1);
00048     Super::free (origPtr);
00049   }
00050 
00051   inline size_t getSize (void * ptr) {
00052     void * origPtr = (void *) ((Add *) ptr - 1);
00053     return Super::getSize (origPtr);
00054   }
00055   
00056 private:
00057   static inline size_t align (size_t sz) {
00058     return (sz + (sizeof(double) - 1)) & ~(sizeof(double) - 1);
00059   }
00060 
00061 };
00062 
00063 };
00064 #endif
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'