From 9266a85b8083ffd12abc2306cd4e9d463ed5308a Mon Sep 17 00:00:00 2001 From: hyzboy Date: Thu, 21 Mar 2024 01:57:51 +0800 Subject: [PATCH] added safe check in SeriesPool --- inc/hgl/type/SeriesPool.h | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/inc/hgl/type/SeriesPool.h b/inc/hgl/type/SeriesPool.h index d480e6c..6589feb 100644 --- a/inc/hgl/type/SeriesPool.h +++ b/inc/hgl/type/SeriesPool.h @@ -4,7 +4,8 @@ namespace hgl { /** - * 序号池 + * 序号池
+ * 没什么用,就是一个序号堆栈而已。 */ template class SeriesPool { @@ -21,10 +22,29 @@ namespace hgl public: + SeriesPool() + { + max_count=0; + series_data=nullptr; + } + SeriesPool(const T &count) { + series_data=nullptr; + Init(count); + } + + bool Init(const T &count) + { + if(series_data) + return(false); + max_count=count; series_data=new T[max_count]; + + if(!series_data) + return(false); + end=series_data+max_count; access=end; @@ -37,6 +57,8 @@ namespace hgl ++p; } } + + return(true); } virtual ~SeriesPool() @@ -47,6 +69,7 @@ namespace hgl bool Acquire(T *sp) { if(!sp)return(false); + if(!series_data)return(false); if(access<=series_data) return(false); @@ -57,6 +80,8 @@ namespace hgl bool Release(const T &s) { + if(!series_data)return(false); + if(access>=end) return(false);