SEO [PR] 爆速!無料ブログ 無料ホームページ開設 無料ライブ放送
メインページ   名前空間一覧   クラス階層   構成   ファイル一覧   名前空間メンバ   構成メンバ   ファイルメンバ  

dKingyoFrameMemory.h

解説を見る。
00001 
00002 
00003 #ifndef __dKingyoFrameMemory_Once_Include__
00004 #define __dKingyoFrameMemory_Once_Include__
00005 
00006 #include "AllLoad.h"
00007 
00008 
00009 namespace dkutil{//begin dkutil
00010 namespace memory{//begin memory
00011 
00012 
00021 
00022 class dKingyoFrameMemory{
00023 protected:
00025     typedef std::list<tugdKingyoFrameMemory > FRAME_LIST;
00026 
00027     FRAME_LIST m_list;//フレーム情報を記録するもの
00028     //スタック形式で使うべし!後ろにpushして保存popで削除
00029 
00030     char *m_frame;//フレームメモリ
00031     size_t m_maxbyte;//今確保しているメモリのバイト単位のサイズ
00032     size_t m_nowbyte;//今の指しているバイト数
00033     inline bool DestructorExecution(const tugdKingyoFrameMemory *get){
00034         if(!(get->Destructor))
00035             return false;
00036         (get->Destructor)();//デストラクタ関数実行
00037         return true;
00038     }
00039 public:
00040     dKingyoFrameMemory(){
00041         m_frame=NULL;
00042         m_list.clear();//リスト初期化
00043     }
00053 
00054     inline int Construct(size_t bytesize){
00055         if(m_frame)
00056             return 1;//すでに確保済みじゃねーかよ!
00057         m_frame= (char *)::malloc(bytesize);
00058         if(!m_frame){
00059             m_frame=NULL;//念のため
00060             m_maxbyte=m_nowbyte=0;
00061             m_list.clear();
00062             return -1;//メモリ確保できなかっただよ!
00063         }
00064         m_maxbyte=bytesize;
00065         m_nowbyte=0;//今はこれだけ
00066         
00067         return 0;
00068     }
00070     inline int Destruct(){
00071         if(!m_frame){
00072             return -1;//あんたヴぁか〜?
00073         }else{
00074             ReleaseList();
00075             ::free(m_frame);
00076             m_frame=NULL;
00077         }
00078         return 0;
00079     }
00080         
00081     virtual ~dKingyoFrameMemory(){
00082         Destruct();
00083     }
00084     inline void *SeekMemory(void *get,DWORD seekbyte){
00085         char *temp=(char *)get;
00086         return (void *)(temp + seekbyte);
00087     }
00089     inline size_t FrameFreeSize(){ return (m_maxbyte - m_nowbyte); }
00091     inline bool isOK(){return ( m_frame != NULL );}
00093     inline DWORD FrameNum(){return (m_list.size());}
00095     inline size_t FrameMaxSize(){return m_maxbyte;}
00097     inline size_t FrameUseSize(){return m_nowbyte;}
00117 
00118     int AttachFrame(void *mem,size_t size,DWORD ID,
00119         VOIDFUNC ReleaseFunc,char *error_str="no comment")
00120     {
00121         if(!isOK())//初期化くらいしろ!
00122             return -1;
00123         if(mem==NULL || size==0 || ID == 0 || 
00124             //ReleaseFunc == NULL ||
00125             error_str == NULL)
00126             return -1;//エラーダッツーノ!引数くらいまともなの入れろ!
00127 
00128         if( FrameFreeSize() < size )
00129             return -1;//フレームメモリのサイズが足りません。
00130 
00131         //更新処理
00132         memcpy((void *)&m_frame[m_nowbyte],mem,size);//メモリコピー
00133         
00134         m_list.push_back(
00135             tugdKingyoFrameMemory(
00136             //  ReleaseFunc,ID,size,&m_frame[m_nowbyte],error_str
00137                 ReleaseFunc,ID,size,m_nowbyte,error_str
00138             )
00139         );
00140         //m_nowbyte += size + 1;//これでいいかな?
00141         m_nowbyte += size;
00142 
00143         char *frametemp = (char *)m_frame;
00144         char *memtemp=(char *)mem;
00145 
00146         return 0;
00147     }
00148     /*
00149     @param error_str="no comment"[in] AttachFrameのerror_strと同じ
00150     */
00152     inline int PopTailFrame(char *error_str="no comment"){
00153         if(!isOK() || m_list.empty() ) return -1;//ヴぁかですね。
00154         DKUTIL_MULTITHREAD_SYNDROME_LOCK();//スレッドロック
00155         const tugdKingyoFrameMemory &p = m_list.back();
00156         DestructorExecution(&p);
00157         //m_nowpoint = p.point;//今空いている領域を指しているポインタを変更(前に戻す)
00158         m_nowbyte -= p.size;//今使っているメモリのバイト数をマイナスする
00159         m_list.pop_back();//削除内容をポップ(削除)する。
00160         DKUTIL_MULTITHREAD_SYNDROME_UNLOCK();//スレッドアンロック
00161     }
00165 
00166     int ReleaseList(DWORD count=0){
00167         
00168         if(m_list.empty()){//空だったら
00169             return -1;
00170         }
00171         
00172         if(count==0){//すべて開放する
00173             DKUTIL_MULTITHREAD_SYNDROME_LOCK();//スレッドロック
00174             FRAME_LIST::reverse_iterator rit;
00175             rit = m_list.rbegin();//逆方向で使う
00176             while(rit != m_list.rend() ){//逆方向で使う。
00177                 DestructorExecution(&(*rit));
00178                 rit++;
00179             }
00180             m_nowbyte=0;//何も使ってない
00181 //          m_nowpoint=m_frame;//フレーム地点にする
00182             m_list.clear();
00183             DKUTIL_MULTITHREAD_SYNDROME_UNLOCK();//スレッドアンロック
00184         }else{
00185             for(DWORD i=0;i<count;i++){//count分リストの後ろからぽっぷする。
00186                 PopTailFrame();
00187             }
00188         }
00189         return 0;
00190     }
00197 
00198     inline char *Sarch(DWORD ID){
00199         FRAME_LIST::iterator it=m_list.begin();
00200         if(ID==0)return NULL;//ID が0はNULLと決まっている。
00201         while(it != m_list.end() ){
00202             if( (*it).ID == ID){
00203                 return &m_frame[(*it).point];
00204                 //return (*it).point;
00205             }
00206             it++;
00207         }
00208         return NULL;
00209     }
00211     inline char *Data(){return m_frame;}
00212     //inline DWORD AssignFrame(void *mem,size_t size){
00213     //  DWORD id=0;
00214         
00215     //}
00216 };
00217 
00218 #   ifdef USE_DKINGYO_OBJECT_TEST
00219 
00220 extern void TestdKingyoFrameMemory();
00221 
00222 #   endif //end of USE_DKINGYO_OBJECT_TEST
00223 
00224 
00225 }//end of memory
00226 }//end of dkutil
00227 
00228 
00229 #endif //end of once include defined

dKingyoUtilClass (dkutil)に対してMon Jun 9 01:32:40 2003に生成されました。 doxygen1.3