source: proiecte/swift/trunk/lib/hoard-371/src/heaplayers/experimental/splitheap.h @ 176

Last change on this file since 176 was 176, checked in by (none), 14 years ago
  • imported repo from "guagal"
File size: 606 bytes
Line 
1#ifndef _SPLITHEAP_H_
2#define _SPLITHEAP_H_
3
4template <class SuperHeap>
5class SplitHeap : public SuperHeap {
6public:
7  inline void * malloc (const size_t sz)
8  {
9    void * ptr = SuperHeap::malloc (sz);
10    if (ptr != NULL) {
11                markInUse (ptr);
12                size_t oldSize = getSize(ptr);
13                if (oldSize <= sz + sizeof(double)) {
14                        return ptr;
15                } else {
16                        void * splitPiece = split (ptr, sz);
17                        if (splitPiece != NULL) {
18                                // printf ("split %d into %d and %d\n", oldSize, getSize(ptr), getSize(splitPiece));
19                                markFree (splitPiece);
20                                SuperHeap::free (splitPiece);
21                        }
22                }
23        }
24    return ptr;
25  }
26};
27
28#endif
Note: See TracBrowser for help on using the repository browser.