/*************************************************************************** * * Copyright (c) 2008 Baidu.com, Inc. All Rights Reserved * $Id: ResourcePool.cpp,v 1.5 2010/04/28 12:45:33 scmpf Exp $ * **************************************************************************/ /** * @file ResourcePool.cpp * @author chenxm(chenxiaoming@baidu.com) * @date 2008/08/06 11:14:09 * @version $Revision: 1.5 $ * @brief * **/ #include #include "bsl/ResourcePool.h" namespace bsl{ /** * @brief 清理所有受托管的资源 * * @return void * @retval * @see * @author chenxm * @date 2009/02/04 15:34:03 **/ void ResourcePool::reset(){ for (block_list_node_t *p_node = _p_alloc_object_list; NULL != p_node; p_node = p_node->p_next ){ for( alloc_object_info_t* p_item = p_node->data + p_node->current; p_item >= p_node->data; --p_item ){ p_item->destructor(p_item->p_object, _mempool); } } _clear_info_list(_p_alloc_object_list); for (block_list_node_t *p_node = _p_alloc_array_list; NULL != p_node; p_node = p_node->p_next ){ for( alloc_array_info_t* p_item = p_node->data + p_node->current; p_item >= p_node->data; --p_item ){ p_item->destructor(p_item->begin, p_item->end, _mempool); } } _clear_info_list(_p_alloc_array_list); for (block_list_node_t *p_node = _p_attach_object_list; NULL != p_node; p_node = p_node->p_next ){ for( attach_object_info_t* p_item = p_node->data + p_node->current; p_item >= p_node->data; --p_item ){ p_item->destructor(p_item->p_object); } } _clear_info_list(_p_attach_object_list); for (block_list_node_t *p_node = _p_attach_array_list; NULL != p_node; p_node = p_node->p_next ){ for( attach_array_info_t* p_item = p_node->data + p_node->current; p_item >= p_node->data; --p_item ){ p_item->destructor(p_item->begin, p_item->end); } } _clear_info_list(_p_attach_array_list); } const char * ResourcePool::_vprintf( alloc_array_info_t& info, size_t hint_capacity, const char *format, va_list ap ){ //参数检查 size_t size = hint_capacity + 1; char* str = static_cast(_mempool.malloc(size)); if ( !str ){ throw bsl::BadAllocException()<