added safe check in SeriesPool

This commit is contained in:
2024-03-21 01:57:51 +08:00
parent ed3e9a468c
commit 9266a85b80

View File

@@ -4,7 +4,8 @@
namespace hgl namespace hgl
{ {
/** /**
* 序号池 * 序号池<br>
* 没什么用,就是一个序号堆栈而已。
*/ */
template<typename T> class SeriesPool template<typename T> class SeriesPool
{ {
@@ -21,10 +22,29 @@ namespace hgl
public: public:
SeriesPool()
{
max_count=0;
series_data=nullptr;
}
SeriesPool(const T &count) SeriesPool(const T &count)
{ {
series_data=nullptr;
Init(count);
}
bool Init(const T &count)
{
if(series_data)
return(false);
max_count=count; max_count=count;
series_data=new T[max_count]; series_data=new T[max_count];
if(!series_data)
return(false);
end=series_data+max_count; end=series_data+max_count;
access=end; access=end;
@@ -37,6 +57,8 @@ namespace hgl
++p; ++p;
} }
} }
return(true);
} }
virtual ~SeriesPool() virtual ~SeriesPool()
@@ -47,6 +69,7 @@ namespace hgl
bool Acquire(T *sp) bool Acquire(T *sp)
{ {
if(!sp)return(false); if(!sp)return(false);
if(!series_data)return(false);
if(access<=series_data) if(access<=series_data)
return(false); return(false);
@@ -57,6 +80,8 @@ namespace hgl
bool Release(const T &s) bool Release(const T &s)
{ {
if(!series_data)return(false);
if(access>=end) if(access>=end)
return(false); return(false);