SourceForge.jp

dkutilAllocatePolicy.h

説明を見る。
00001 
00008 #ifndef _dkutilAllocatePolicy__h_
00009 #define _dkutilAllocatePolicy__h_
00010 
00011 #include "dKingyoMacro.h"
00012 #include "dkutilDefinedC.h"
00013 
00014 
00015 
00016 
00017 namespace dkutil{
00018 
00019 
00020 namespace policy{
00021 
00022 
00023 struct allocate_policy_malloc{
00024 
00025     void * malloc(const size_t bytes)const
00026   { 
00027         void *p = DKUTIL_SAFE_MALLOC(bytes); 
00028         if(!p) return NULL;
00029         memset(p,0,bytes);
00030         return p; 
00031     }
00032     void free(void * block)const
00033   { 
00034         DKUTIL_SAFE_FREE(block);
00035     }
00036     void *realloc(void *block,size_t size)const{
00037         return (void *)DKUTIL_SAFE_REALLOC(block,size);
00038     }
00039 };
00040 
00041 
00042 struct allocate_policy_globalalloc{
00043     void * malloc(const size_t bytes)const
00044   { return ::GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT,bytes); }
00045 
00046     void free(void * block)const
00047   { 
00048         if(block){
00049             ::GlobalFree(block);
00050         }
00051     }
00052     void *realloc(void *block,size_t size)const{
00053         if(block){
00054             return (void *)::GlobalReAlloc(block,size,NULL);//わからないから第三引数はNULLで^^;
00055         }else{
00056             return malloc(size);
00057         }
00058     }
00059 
00060 };
00061 
00065 
00066 template<class IMPL>
00067 class AllocatorInterface{
00068 public:
00069     typedef std::size_t size_type;
00070   typedef std::ptrdiff_t difference_type;
00071 private:
00072     IMPL ma;
00073 public:
00075     BYTE *Alloc(int size)const{
00076         return ma.malloc(size);
00077     }
00079     void Free(BYTE *pb)const{
00080         ma.free(pb);
00081     }
00082     BYTE* ReAlloc(BYTE *ptr,int size)const{
00083         return (BYTE *)ma.realloc(ptr,size);
00084     }
00085 
00087     char * malloc(const size_type bytes)const
00088   { return (char *)ma.malloc(bytes); }
00090     void free(char * const block)const
00091   { ma.free(block); }
00092 
00093     char *realloc(char *block,size_type size)const{
00094         return (char *)ma.realloc((void *)block,size);
00095     }
00096 };
00097 
00098 
00099 typedef AllocatorInterface<allocate_policy_globalalloc> Win32SafeAllocator;
00100 typedef AllocatorInterface<allocate_policy_malloc> DefaultAllocator; 
00101 
00102 
00103 }//end of policy namespace
00104 
00105 }//end of dkutil namespace
00106 
00107 #endif //end of include once
00108 

dkutil 1.02リリース前 d金魚専用マニュアルバージョンに対してSun Dec 28 21:23:07 2003に生成されました。 doxygen 1.3.5