This Trac instance is not used for development anymore!

We migrated our development workflow to git and Gitea.
To test the future redirection, replace trac by ariadne in the page URL.

Changeset 10049 for ps


Ignore:
Timestamp:
08/21/11 12:30:35 (13 years ago)
Author:
Jan Wassenberg
Message:

remove Bucket allocator (superseded by upcoming Arena/Pool with expandable Storage policies)

Location:
ps/trunk/source/lib/allocators
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • ps/trunk/source/lib/allocators/bucket.cpp

    r9410 r10049  
    3434// power-of-2 isn't required; value is arbitrary.
    3535const size_t bucketSize = 4000;
     36
     37
     38template<typename T, class Allocator = Allocator_Heap, size_t bucketSize = pageSize>
     39class Buckets
     40{
     41public:
     42    // (must round up because freelist stores pointers inside objects)
     43    static const size_t objectSize = ROUND_UP(sizeof(T), sizeof(intptr_t));
     44
     45    Buckets(size_t maxObjects)
     46        : storage(maxObjects*objectSize)
     47    {
     48    }
     49
     50    size_t RemainingObjects()
     51    {
     52        return (storage.MaxCapacity() - end) / objectSize;
     53    }
     54
     55    T* Allocate()
     56    {
     57        void* p = mem_freelist_Detach(freelist);
     58        if(p)
     59        {
     60            ASSERT(Contains(p));
     61            return (T*)p;
     62        }
     63
     64        return (T*)StorageAppend(storage, end, objectSize);
     65    }
     66
     67    void Deallocate(T* p)
     68    {
     69        ASSERT(Contains(p));
     70        mem_freelist_AddToFront(freelist, p);
     71    }
     72
     73private:
     74    Storage storage;
     75    size_t end;
     76    void* freelist;
     77};
     78
    3679
    3780
     
    132175    return ret;
    133176}
    134 
    135 
    136 void bucket_free(Bucket* b, void* el)
    137 {
    138     if(b->el_size == 0)
    139     {
    140         DEBUG_WARN_ERR(ERR::LOGIC); // cannot free variable-size items
    141         return;
    142     }
    143 
    144     mem_freelist_AddToFront(b->freelist, el);
    145 
    146     // note: checking if <el> was actually allocated from <b> is difficult:
    147     // it may not be in the currently open bucket, so we'd have to
    148     // iterate over the list - too much work.
    149 }
  • ps/trunk/source/lib/allocators/bucket.h

    r9410 r10049  
    100100LIB_API void* bucket_fast_alloc(Bucket* b);
    101101
    102 /**
    103  * make an entry available for reuse in the given Bucket.
    104  *
    105  * this is not allowed if created for variable-size elements.
    106  * rationale: avoids having to pass el_size here and compare with size when
    107  * allocating; also prevents fragmentation and leaking memory.
    108  *
    109  * @param b Bucket*
    110  * @param el entry allocated via bucket_alloc.
    111  **/
    112 LIB_API void bucket_free(Bucket* b, void* el);
    113 
    114102#endif  // #ifndef INCLUDED_ALLOCATORS_BUCKET
Note: See TracChangeset for help on using the changeset viewer.