Eneboo - Documentación para desarrolladores
|
00001 #ifndef _SPLITHEAP_H_ 00002 #define _SPLITHEAP_H_ 00003 00004 template <class SuperHeap> 00005 class SplitHeap : public SuperHeap { 00006 public: 00007 inline void * malloc (const size_t sz) 00008 { 00009 void * ptr = SuperHeap::malloc (sz); 00010 if (ptr != NULL) { 00011 markInUse (ptr); 00012 size_t oldSize = getSize(ptr); 00013 if (oldSize <= sz + sizeof(double)) { 00014 return ptr; 00015 } else { 00016 void * splitPiece = split (ptr, sz); 00017 if (splitPiece != NULL) { 00018 // printf ("split %d into %d and %d\n", oldSize, getSize(ptr), getSize(splitPiece)); 00019 markFree (splitPiece); 00020 SuperHeap::free (splitPiece); 00021 } 00022 } 00023 } 00024 return ptr; 00025 } 00026 }; 00027 00028 #endif