Opened 13 years ago

Closed 12 years ago

#3349 closed Bugs (fixed)

ordered_malloc not always keeps the free list ordered.

Reported by: Xiaohan Wang <wangxiaohan@…> Owned by: Chris Newbold
Milestone: Boost 1.40.0 Component: pool
Version: Boost 1.39.0 Severity: Problem
Keywords: pool, ordered_malloc, add_block Cc: boostpool@…

Description

Hello,

In function

template <typename UserAllocator>
void * pool<UserAllocator>::ordered_malloc(const size_type n)

in pool.hpp, I saw the code below along with the comments:

// Split up block so we can use what wasn't requested
  //  (we can use "add_block" here because we know that
  //  the free list is empty, so we don't have to use
  //  the slower ordered version)
  if (next_size > num_chunks)
    store().add_block(node.begin() + num_chunks * partition_size,
        node.element_size() - num_chunks * partition_size, partition_size);

However, here I don't see why the free list must be empty. In my case, the free list is not empty. The new free chunks are added to the beginning of the free list and all existing ones are appended to the new ones, making the list out of order.

I guess using ordered_add_block could easily solve this problem.

Change History (3)

comment:1 by Xiaohan Wang <wangxiaohan@…>, 13 years ago

BTW, I wrote a simple program to show this. The variable "any_memory_released" is false after the release because the free list is out of order. If we change the "add_block" to "add_ordered_block" then "any_memory_released" is true.

int main()
{
    pool<> p(256, 4);

    void* pBlock1 = p.ordered_malloc( 1 );
    void* pBlock2 = p.ordered_malloc( 4 );
    
    p.ordered_free( pBlock1 );

    bool any_memory_released = p.release_memory();

    cout << "Any memory released? " << any_memory_released << endl;
}

comment:2 by John Maddock, 12 years ago

Cc: boostpool@… added

comment:3 by anonymous, 12 years ago

Resolution: fixed
Status: newclosed

This was fixed as part of [67792]

Note: See TracTickets for help on using tickets.