acl/lib_acl_cpp/include/acl_cpp/stdlib/dbuf_pool.hpp

594 lines
14 KiB
C++
Raw Normal View History

#pragma once
2015-01-26 19:58:02 +08:00
#include "acl_cpp/acl_cpp_define.hpp"
#include "acl_cpp/stdlib/noncopyable.hpp"
2015-11-09 22:11:21 +08:00
#include <vector>
struct ACL_DBUF_POOL;
namespace acl
{
2015-01-26 19:58:02 +08:00
/**
2015-11-09 22:11:21 +08:00
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>Ե<EFBFBD><EFBFBD>ͷţ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʺ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҪƵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һЩ<EFBFBD><EFBFBD>С<EFBFBD><EFBFBD><EFBFBD>ȵ<EFBFBD>С<EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>ã<EFBFBD>
2015-01-26 19:58:02 +08:00
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD>װ<EFBFBD><EFBFBD> lib_acl <EFBFBD>е<EFBFBD> ACL_DBUF_POOL <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
2015-11-09 22:11:21 +08:00
2015-01-26 19:58:02 +08:00
class ACL_CPP_API dbuf_pool
{
public:
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̬<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
dbuf_pool();
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD>̬<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> destroy
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>̬<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
void destroy();
/**
2015-11-09 22:11:21 +08:00
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> new/delete <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ dbuf_pool <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϣ<EFBFBD>
* <EFBFBD>Ӷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> malloc/free <EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD>
2015-11-09 22:11:21 +08:00
* @param size {size_t} <EFBFBD>ɱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> dbuf_pool <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD><EFBFBD>ȴ<EFBFBD>С
* @param nblock {size_t} <EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD>4096<EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><EFBFBD><EFBFBD>
*/
2015-11-09 22:11:21 +08:00
void *operator new(size_t size, size_t nblock = 2);
#if defined(_WIN32) || defined(_WIN64)
void operator delete(void* ptr, size_t);
#else
void operator delete(void* ptr);
2015-11-09 22:11:21 +08:00
#endif
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD>ص<EFBFBD>״̬<EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD>ʹ<EFBFBD>ø<EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD>ض<EFBFBD><EFBFBD><EFBFBD>
2015-11-09 22:11:21 +08:00
* @param reserve {size_t} <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ > 0<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><EFBFBD>
* <EFBFBD>ô<EFBFBD>С<EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD>ڵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><EFBFBD>ڸ<EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD>ض<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD>С
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>򷵻<EFBFBD> false
*/
2015-11-09 22:11:21 +08:00
bool dbuf_reset(size_t reserve = 0);
2015-01-26 19:58:02 +08:00
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȵ<EFBFBD><EFBFBD>ڴ<EFBFBD>
2015-11-09 22:11:21 +08:00
* @param len {size_t} <EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>ȣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD>Ƚ<EFBFBD>Сʱ(С<EFBFBD>ڹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD>е<EFBFBD> block_size)ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> dbuf_pool <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϣ<EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD>ϴ<EFBFBD>ʱ<EFBFBD><EFBFBD>ֱ<EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD> malloc <EFBFBD><EFBFBD><EFBFBD>з<EFBFBD><EFBFBD><EFBFBD>
2015-01-26 19:58:02 +08:00
* @return {void*} <EFBFBD>·<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD>ַ
*/
void* dbuf_alloc(size_t len);
2015-01-26 19:58:02 +08:00
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȵ<EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param len {size_t} <EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD>
* @return {void*} <EFBFBD>·<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD>ַ
*/
void* dbuf_calloc(size_t len);
2015-01-26 19:58:02 +08:00
/**
2015-11-09 22:11:21 +08:00
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̬<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>и<EFBFBD><EFBFBD>ƣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> strdup
2015-01-26 19:58:02 +08:00
* @param s {const char*} Դ<EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>
* @return {char*} <EFBFBD>¸<EFBFBD><EFBFBD>Ƶ<EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
*/
char* dbuf_strdup(const char* s);
2015-01-26 19:58:02 +08:00
2015-11-09 22:11:21 +08:00
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̬<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>и<EFBFBD><EFBFBD>ƣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> strdup
* @param s {const char*} Դ<EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>
* @param len {size_t} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>󳤶<EFBFBD>
* @return {char*} <EFBFBD>¸<EFBFBD><EFBFBD>Ƶ<EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
*/
char* dbuf_strndup(const char* s, size_t len);
2015-01-26 19:58:02 +08:00
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݶ<EFBFBD>̬<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD><EFBFBD>и<EFBFBD><EFBFBD><EFBFBD>
2015-11-09 22:11:21 +08:00
* @param addr {const void*} Դ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD>ַ
2015-01-26 19:58:02 +08:00
* @param len {size_t} Դ<EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>
* @return {void*} <EFBFBD>¸<EFBFBD><EFBFBD>Ƶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>ַ
*/
2015-11-09 22:11:21 +08:00
void* dbuf_memdup(const void* addr, size_t len);
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD>ط<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
* @param addr {const void*} <EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD>ط<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD>ַ
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD>ط<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷŶ<EFBFBD><EFBFBD>Σ<EFBFBD><EFBFBD>򷵻<EFBFBD> false
*/
bool dbuf_free(const void* addr);
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD>ط<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD>ε<EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> dbuf_reset ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD>ͷŵ<EFBFBD>
* @param addr {const void*} <EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD>ط<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD>ַ
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD>ط<EFBFBD><EFBFBD><EFBFBD>򷵻<EFBFBD> false
*/
bool dbuf_keep(const void* addr);
/**
* ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD>ط<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD>ε<EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD>ڵ<EFBFBD><EFBFBD><EFBFBD> dbuf_reset ʱ<EFBFBD><EFBFBD><EFBFBD>ͷŵ<EFBFBD>
* @param addr {const void*} <EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD>ط<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD>ַ
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD>ط<EFBFBD><EFBFBD><EFBFBD>򷵻<EFBFBD> false
*/
bool dbuf_unkeep(const void* addr);
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD> ACL_DBUF_POOL <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD> C <EFBFBD>ӿڵ<EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD>ض<EFBFBD><EFBFBD><EFBFBD>
* @return {ACL_DBUF_POOL*}
*/
ACL_DBUF_POOL *get_dbuf()
{
return pool_;
}
private:
ACL_DBUF_POOL* pool_;
size_t mysize_;
2015-11-09 22:11:21 +08:00
public:
~dbuf_pool();
};
2015-11-09 22:11:21 +08:00
/**
* sample:
* void test()
* {
* acl::dbuf_pool* dbuf = new acl::dbuf_pool;
* for (int i = 0; i < 1000; i++)
* {
* char* ptr = dbuf->dbuf_strdup("hello world!");
* printf("%s\r\n", p);
* }
* dbuf->destroy();
*
* // <20><><EFBFBD><EFBFBD> dbuf <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
* dbuf = new(8) acl::dbuf_pool;
* for (int i = 0; i < 1000; i++)
* {
* ptr = dbuf->dbuf_strdup("hello world!");
* printf("%s\r\n", p);
* }
*
* // <20><><EFBFBD><EFBFBD> dbuf <20><><EFBFBD><EFBFBD>
* dbuf->destroy();
* }
*
*/
//////////////////////////////////////////////////////////////////////////////
class dbuf_guard;
/**
* <EFBFBD>ڻ<EFBFBD>ڴ<EFBFBD><EFBFBD>ض<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ķ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
class ACL_CPP_API dbuf_obj
{
public:
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param guard {dbuf_guard*} <EFBFBD>ò<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǿ<EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* dbuf_guard <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͳһ<EFBFBD><EFBFBD><EFBFBD>٣<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ò<EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>գ<EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD>Ӧ
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> dbuf_guard::push_back <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͳһ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
dbuf_obj(dbuf_guard* guard = NULL);
virtual ~dbuf_obj() {}
/**
* <EFBFBD><EFBFBD><EFBFBD>øö<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> dbuf_guard <EFBFBD>е<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><EFBFBD>±<EFBFBD>λ<EFBFBD><EFBFBD>
* @return {int} <EFBFBD><EFBFBD><EFBFBD>ظö<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> dbuf_guard <EFBFBD>е<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><EFBFBD>±<EFBFBD>λ<EFBFBD>ã<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>б<EFBFBD> dbuf_guard <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD>򷵻<EFBFBD> -1<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>п<EFBFBD><EFBFBD>ܻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>й
*/
int pos() const
{
return pos_;
}
/**
* <EFBFBD><EFBFBD><EFBFBD>ع<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> dbuf_guard <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @return {dbuf_guard*}
*/
dbuf_guard* get_guard() const
{
return guard_;
}
private:
friend class dbuf_guard;
// <20><>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> dbuf_guard <20><><EFBFBD><EFBFBD>
dbuf_guard* guard_;
// <20>ñ<EFBFBD><C3B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> dbuf_guard <20><><EFBFBD><EFBFBD>ʹ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӱ<EFBFBD>ȫ<EFBFBD><C8AB>
int nrefer_;
// <20>ö<EFBFBD><C3B6><EFBFBD><EFBFBD><EFBFBD> dbuf_guard <20><><EFBFBD><EFBFBD><EFBFBD>м<EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
int pos_;
2015-11-09 22:11:21 +08:00
};
/**
* <EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD>ع<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɸ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> dbuf_pool <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ķ<EFBFBD><EFBFBD>󣬵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>dbuf_pool <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷš<EFBFBD>
*/
class ACL_CPP_API dbuf_guard : public noncopyable
2015-11-09 22:11:21 +08:00
{
public:
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param dbuf {dbuf_pool*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD>ض<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǿ<EFBFBD>ʱ<EFBFBD><EFBFBD>dbuf <EFBFBD><EFBFBD><EFBFBD><EFBFBD> dbuf_guard
* <EFBFBD>ӹܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>գ<EFBFBD><EFBFBD>򱾹<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD> dbuf_pool <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param capacity {size_t} <EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> objs_ <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
dbuf_guard(dbuf_pool* dbuf, size_t capacity = 100);
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param nblock {size_t} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> dbuf_pool <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD>(4096)<EFBFBD>ı<EFBFBD><EFBFBD><EFBFBD>
* @param capacity {size_t} <EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> objs_ <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2015-11-09 22:11:21 +08:00
*/
dbuf_guard(size_t nblock = 2, size_t capacity = 100);
2015-11-09 22:11:21 +08:00
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> dbuf_pool <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
~dbuf_guard();
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> dbuf_pool::dbuf_reset
* @param reserve {size_t}
* @return {bool}
*/
bool dbuf_reset(size_t reserve = 0);
2015-11-09 22:11:21 +08:00
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> dbuf_pool::dbuf_alloc
* @param len {size_t}
* @return {void*}
*/
void* dbuf_alloc(size_t len)
{
return dbuf_->dbuf_alloc(len);
}
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> dbuf_pool::dbuf_calloc
* @param len {size_t}
* @return {void*}
*/
void* dbuf_calloc(size_t len)
{
return dbuf_->dbuf_calloc(len);
}
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> dbuf_pool::dbuf_strdup
* @param s {const char*}
* @return {char*}
*/
char* dbuf_strdup(const char* s)
{
return dbuf_->dbuf_strdup(s);
}
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> dbuf_pool::dbuf_strndup
* @param s {const char*}
* @param len {size_t}
* @return {char*}
*/
char* dbuf_strndup(const char* s, size_t len)
{
return dbuf_->dbuf_strndup(s, len);
}
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> dbuf_pool::dbuf_memdup
* @param addr {const void*}
* @param len {size_t}
* @return {void*}
*/
void* dbuf_memdup(const void* addr, size_t len)
{
return dbuf_->dbuf_memdup(addr, len);
}
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> dbuf_pool::dbuf_free
* @param addr {const void*}
* @return {bool}
*/
bool dbuf_free(const void* addr)
{
return dbuf_->dbuf_free(addr);
}
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> dbuf_pool::dbuf_keep
* @param addr {const void*}
* @return {bool}
*/
bool dbuf_keep(const void* addr)
{
return dbuf_->dbuf_keep(addr);
}
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> dbuf_pool::dbuf_unkeep
* @param addr {const void*}
* @return {bool}
*/
bool dbuf_unkeep(const void* addr)
{
return dbuf_->dbuf_unkeep(addr);
}
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> dbuf_pool <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @return {acl::dbuf_pool&}
*/
acl::dbuf_pool& get_dbuf() const
{
return *dbuf_;
}
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ñ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> dbuf_pool <EFBFBD>Ϸ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> dbuf_obj <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>󽻸<EFBFBD>
* dbuf_guard <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͳһ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͻ<EFBFBD><EFBFBD><EFBFBD>ͬһ<EFBFBD><EFBFBD> dbuf_obj <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ
* ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> dbuf_guard <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>й<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>򽫻<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD><EFBFBD>ͷ<EFBFBD>
2015-11-09 22:11:21 +08:00
* @param obj {dbuf_obj*}
* @return {int} <EFBFBD><EFBFBD><EFBFBD><EFBFBD> obj <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> dbuf_obj <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><EFBFBD>±<EFBFBD>λ<EFBFBD>ã<EFBFBD>
* dbuf_guard <EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD> dbuf_obj <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĺ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>з<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӻ<EFBFBD><EFBFBD>ƣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ե<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD>ͬһ<EFBFBD><EFBFBD> dbuf_obj <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬһ<EFBFBD><EFBFBD> dbuf_guard <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD>ֻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>
2015-11-09 22:11:21 +08:00
*/
int push_back(dbuf_obj* obj);
/**
* <EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>ǰ<EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>й<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ķ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @return {size_t}
*/
size_t size() const
{
return size_;
2015-11-09 22:11:21 +08:00
}
/**
* <EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>ǰ<EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>й<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ķ<EFBFBD><EFBFBD>󼯺ϣ<EFBFBD><EFBFBD>ú<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> size() <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>ã<EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַԽ<EFBFBD><EFBFBD>
* @return {dbuf_obj**} <EFBFBD><EFBFBD><EFBFBD><EFBFBD> dbuf_obj <EFBFBD><EFBFBD><EFBFBD>󼯺ϣ<EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD>ط<EFBFBD> NULL ֵ<EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD>С<EFBFBD><EFBFBD> size() <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2015-11-09 22:11:21 +08:00
*/
dbuf_obj** get_objs() const
2015-11-09 22:11:21 +08:00
{
return objs_;
}
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD>±<EFBFBD><EFBFBD>Ķ<EFBFBD><EFBFBD><EFBFBD>
* @param pos {size_t} ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>±<EFBFBD>λ<EFBFBD>ã<EFBFBD><EFBFBD><EFBFBD>ӦԽ<EFBFBD><EFBFBD>
* @return {dbuf_obj*} <EFBFBD><EFBFBD><EFBFBD>±<EFBFBD>λ<EFBFBD><EFBFBD>Խ<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> NULL
*/
dbuf_obj* operator[](size_t pos) const;
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD>±<EFBFBD><EFBFBD>Ķ<EFBFBD><EFBFBD><EFBFBD>
* @param pos {size_t} ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>±<EFBFBD>λ<EFBFBD>ã<EFBFBD><EFBFBD><EFBFBD>ӦԽ<EFBFBD><EFBFBD>
* @return {dbuf_obj*} <EFBFBD><EFBFBD><EFBFBD>±<EFBFBD>λ<EFBFBD><EFBFBD>Խ<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> NULL
*/
dbuf_obj* get(size_t pos) const;
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڽ<EFBFBD> objs_ <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ÿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ռ<EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD>ȱʡֵΪ 100
* @param incr {size_t}
*/
void set_increment(size_t incr);
public:
template <typename T>
T* create()
{
T* t = new (dbuf_alloc(sizeof(T))) T();
(void) push_back(t);
return t;
}
template <typename T, typename P1>
T* create(P1 p)
{
T* t = new (dbuf_alloc(sizeof(T))) T(p);
(void) push_back(t);
return t;
}
template <typename T, typename P1, typename P2>
T* create(P1 p1, P2 p2)
{
T* t = new (dbuf_alloc(sizeof(T))) T(p1, p2);
(void) push_back(t);
return t;
}
template <typename T, typename P1, typename P2, typename P3>
T* create(P1 p1, P2 p2, P3 p3)
{
T* t = new (dbuf_alloc(sizeof(T))) T(p1, p2, p3);
(void) push_back(t);
return t;
}
template <typename T, typename P1, typename P2, typename P3,
typename P4>
T* create(P1 p1, P2 p2, P3 p3, P4 p4)
{
T* t = new (dbuf_alloc(sizeof(T))) T(p1, p2, p3, p4);
(void) push_back(t);
return t;
}
template <typename T, typename P1, typename P2, typename P3,
typename P4, typename P5>
T* create(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5)
{
T* t = new (dbuf_alloc(sizeof(T))) T(p1, p2, p3, p4, p5);
(void) push_back(t);
return t;
}
template <typename T, typename P1, typename P2, typename P3,
typename P4, typename P5, typename P6>
T* create(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6)
{
T* t = new (dbuf_alloc(sizeof(T))) T(p1, p2, p3, p4, p5, p6);
(void) push_back(t);
return t;
}
template <typename T, typename P1, typename P2, typename P3,
typename P4, typename P5, typename P6, typename P7>
T* create(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7)
{
T* t = new (dbuf_alloc(sizeof(T)))
T(p1, p2, p3, p4, p5, p6, p7);
(void) push_back(t);
return t;
}
template <typename T, typename P1, typename P2, typename P3,
typename P4, typename P5, typename P6, typename P7,
typename P8>
T* create(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8)
{
T* t = new (dbuf_alloc(sizeof(T)))
T(p1, p2, p3, p4, p5, p6, p7, p8);
(void) push_back(t);
return t;
}
template <typename T, typename P1, typename P2, typename P3,
typename P4, typename P5, typename P6, typename P7,
typename P8,typename P9>
T* create(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7,
P8 p8, P9 p9)
{
T* t = new (dbuf_alloc(sizeof(T)))
T(p1, p2, p3, p4, p5, p6, p7, p8, p9);
(void) push_back(t);
return t;
}
template <typename T, typename P1, typename P2, typename P3,
typename P4, typename P5, typename P6, typename P7,
typename P8, typename P9, typename P10>
T* create(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7,
P8 p8, P9 p9, P10 p10)
{
T* t = new (dbuf_alloc(sizeof(T)))
T(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
(void) push_back(t);
return t;
}
2015-11-09 22:11:21 +08:00
private:
size_t nblock_; // <20>ڲ<EFBFBD><DAB2>Խ<EFBFBD> dbuf_pool <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>ĵ<EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>
dbuf_pool* dbuf_; // <20>ڴ<EFBFBD><DAB4>ض<EFBFBD><D8B6><EFBFBD>
// <20>˴<EFBFBD>֮<EFBFBD><D6AE><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD>ʵ<EFBFBD>ֵ<EFBFBD> dbuf_obj <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>󣬶<EFBFBD>û<EFBFBD><C3BB>ʹ<EFBFBD><CAB9> std::vector<6F><72>
// һ<><D2BB><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҳ<EFBFBD><D2B2> dbuf_pool <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><D4B1><EFBFBD>
// std::vector <20>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>ڴ治<DAB4>ɿ<EFBFBD><C9BF><EFBFBD>
dbuf_obj** objs_; // <20>洢 dbuf_obj <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
size_t size_; // <20><EFBFBD><E6B4A2> objs_ <20>еĶ<D0B5><C4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
size_t capacity_; // objs_ <20><><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD>С
size_t incr_; // objs_ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// <20><><EFBFBD><EFBFBD> objs_ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀռ<C4BF>
void extend_objs();
2015-11-09 22:11:21 +08:00
};
/**
* sample1:
2015-11-09 22:11:21 +08:00
* // <20>̳<EFBFBD> acl::dbuf_obj <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* class myobj1 : public acl::dbuf_obj
2015-11-09 22:11:21 +08:00
* {
* public:
* // <20><> guard <20><><EFBFBD>󴫵ݸ<F3B4ABB5><DDB8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>󣬻<EFBFBD><F3A3ACBB><EFBFBD><E0BDAB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> guard <20>Ķ<EFBFBD><C4B6>󼯺<EFBFBD><F3BCAFBA><EFBFBD>
* myobj1(acl::dbuf_guard* guard) : dbuf_obj(guard) {}
2015-11-09 22:11:21 +08:00
*
* void doit()
* {
* printf("hello world!\r\n");
* }
*
* private:
* ~myobj1() {}
2015-11-09 22:11:21 +08:00
* };
*
* void test()
* {
* acl::dbuf_guard dbuf;
2015-11-09 22:11:21 +08:00
*
* // <20><> dbuf_guard <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD><EFBFBD>̬ 100 <20><> myobj <20><><EFBFBD><EFBFBD>
* for (int i = 0; i < 100; i++)
* {
* // <20><> guard <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD><EFBFBD>̬ myobj <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҽ<EFBFBD> guard <20><>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* myobj* obj = new (dbuf.dbuf_alloc(sizeof(myobj))) myobj(&dbuf);
2015-11-09 22:11:21 +08:00
* obj->doit();
* }
*
* // <20><> dbuf <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E6B4B4><EFBFBD>Ķ<EFBFBD>̬<EFBFBD><CCAC><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>
* }
*
* // sample2
* class myobj2 : public acl::dbuf_obj
* {
* public:
* myobj2() {}
*
* void doit()
* {
* printf("hello world\r\n");
* }
*
* private:
* ~myobj2() {}
* };
*
* void test2()
* {
* acl::dbuf_guard dbuf;
*
* for (int i = 0; i < 100; i++)
* {
* myobj2* obj = dbuf.create<myobj2>();
* obj->doit();
* }
* }
*
* // sample3
* class myobj2 : public acl::dbuf_obj
* {
* public:
* myobj2(int i) : i_(i) {}
*
* void doit()
* {
* printf("hello world, i: %d\r\n", i_);
* }
*
* private:
* ~myobj2() {}
*
* private:
* int i_;
* };
*
* void test2()
* {
* acl::dbuf_guard dbuf;
*
* for (int i = 0; i < 100; i++)
* {
* myobj2* obj = dbuf.create<myobj2>(i);
* obj->doit();
* }
2015-11-09 22:11:21 +08:00
* }
*/
} // namespace acl