Changeset 1811


Ignore:
Timestamp:
Dec 23, 2011, 2:29:59 PM (8 years ago)
Author:
ksherdy
Message:

"Minor modifications."

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/allocator.hpp

    r1763 r1811  
    11/*
    22 * allocator.hpp - Memory allocation.
     3 * Created on: 18-December-2011
     4 * Author: Ken Herdy
     5 *
     6 *
    37 */
    48
     
    1822class pool_allocator {
    1923public:
    20         void * allocate (uint64_t n, uint64_t & alloc_segment_size);
    21         void * allocate_aligned (uint64_t n, uint64_t & alloc_segment_size);
     24        /* n - bytes requested, allocd_segment_size - bytes allocated */
     25        void * allocate (uint64_t n, uint64_t & allocd_segment_size);
     26        void * allocate_aligned (uint64_t n, uint64_t & allocd_segment_size);
    2227        void destroy ();
    2328protected:
     
    2833/* Fast Memory Pool Allocator - Trade memory for speed.
    2934 *
    30  * Allocates BASE_SIZE stack bytes.
     35 * Allocates BASE_SIZE bytes on the stack.
    3136 * Allocates additional bytes on the heap.
    32  * Returns aligned raw data pointers (void *).
    33  * Simultaneous deallocation.
     37 * Coterminal deallocation.
     38 * Allocation returns void * pointer to memory block, returns number of bytes allocated.
    3439 *
    3540 */
     
    4853        ~fast_pool_allocator() {}
    4954
    50         void * allocate(uint64_t n, uint64_t & alloc_segment_size) {
     55        void * allocate(uint64_t n, uint64_t & allocd_segment_size) {
    5156                if(n > available) {
    52                                         cout << "Add Segment" << endl;
    5357                        segment_size = next_segment_size(n);
    5458
     
    7579                uint64_t address = reinterpret_cast<uint64_t>(&(tail->segment[i]));
    7680
    77                 alloc_segment_size = available;
     81                allocd_segment_size = available;
    7882                available -= n;
    7983
     
    8185        }
    8286
    83         void * allocate_aligned(uint64_t n, uint64_t & alloc_segment_size) {
     87        void * allocate_aligned(uint64_t n, uint64_t & allocd_segment_size) {
    8488                uint64_t n_padded = (n+ALIGNMENT-1);
    8589
     
    111115                uint64_t padding = ((address % ALIGNMENT) == 0) ? 0 :  ALIGNMENT - (address % ALIGNMENT);
    112116
    113                 alloc_segment_size = available;
     117                allocd_segment_size = available;
    114118                available -= (padding + n);
    115119
     
    128132                        crt = next;
    129133                        next = NULL;
    130                         cout << "Del Segment" << endl;
    131134                }
    132135        }
Note: See TracChangeset for help on using the changeset viewer.