commit 2025-09-20 10:16 edit member fun of ZCAllocClass ZCppMain/ZMainHead.H

This commit is contained in:
2025-09-20 10:17:07 +09:00
parent b893f0884e
commit 6238184f8d
2 changed files with 27 additions and 17 deletions

View File

@ -3252,25 +3252,35 @@ namespace ZNsMain
/////////////////////////////////////////////////////////////////*/ /////////////////////////////////////////////////////////////////*/
template<typename TType> class ZtCAllocClass : template<typename TType> class ZtCAllocClass : public ZCAllocator
public ZCAllocator
//////////////////////////////////////////////
{ {
public: public:
#if(_CODE_OLD_)
TType* NewMem (size_t AL_AllocSize){return (TType*)::malloc(AL_AllocSize) ;} TType* NewMem (size_t AL_AllocSize){return (TType*)::malloc(AL_AllocSize) ;}
TType* NewArrMem(size_t AL_AllocSize){return (TType*)::malloc(AL_AllocSize*sizeof(TType));} TType* NewArrMem(size_t AL_AllocSize){return (TType*)::malloc(AL_AllocSize*sizeof(TType));}
public: public:
void DeleteMem(void* AP_Void){if(AP_Void!=0) ::free(AP_Void);} void DeleteMem(void* AP_Void){if(AP_Void!=0) ::free(AP_Void);}
#else
TType* InitMem (size_t AL_AllocSize){return (TType*)::malloc(AL_AllocSize) ;}
TType* InitArrMem(size_t AL_AllocSize){return (TType*)::malloc(AL_AllocSize*sizeof(TType));}
public:
void FiniMem (void* AP_Void){if(AP_Void!=0) ::free(AP_Void);}
#endif
public: public:
};/* };/*
template<typename TType> class ZtCAllocClass*/ template<typename TType> class ZtCAllocClass : public ZCAllocator*/
class ZCAllocClass : public ZCAllocator class ZCAllocClass : public ZCAllocator
{ {
public: public:
#if(_CODE_OLD_)
void* NewMem (size_t AL_AllocSize){return ::malloc(AL_AllocSize) ;} void* NewMem (size_t AL_AllocSize){return ::malloc(AL_AllocSize) ;}
void DeleteMem(void* AP_Void ){if(AP_Void!=0) ::free(AP_Void);} void DeleteMem(void* AP_Void ){if(AP_Void!=0) ::free(AP_Void);}
#else
void* InitMem (size_t AL_AllocSize){return ::malloc(AL_AllocSize) ;}
void FiniMem (void* AP_Void ){if(AP_Void!=0) ::free(AP_Void);}
#endif
public: public:
};/* };/*
class ZCAllocClass : public ZCAllocator*/ class ZCAllocClass : public ZCAllocator*/
@ -4296,7 +4306,7 @@ namespace ZNsMain
ZtCObjNew() ZtCObjNew()
{ {
mp_StTypeRefCnt = (StTypeRefCnt*) mp_StTypeRefCnt = (StTypeRefCnt*)
this->ZCAllocator::NewMem(sizeof(StTypeRefCnt)); this->ZCAllocator::InitMem(sizeof(StTypeRefCnt));
mp_StTypeRefCnt->MI_RefCount = 1 ; mp_StTypeRefCnt->MI_RefCount = 1 ;
new(&mp_StTypeRefCnt->MO_TypeData) TypeData; new(&mp_StTypeRefCnt->MO_TypeData) TypeData;
@ -4306,7 +4316,7 @@ namespace ZNsMain
ZtCObjNew(const TypeData& AR_TypeData) ZtCObjNew(const TypeData& AR_TypeData)
{ {
mp_StTypeRefCnt = (StTypeRefCnt*) mp_StTypeRefCnt = (StTypeRefCnt*)
this->ZCAllocator::NewMem(sizeof(StTypeRefCnt)); this->ZCAllocator::InitMem(sizeof(StTypeRefCnt));
mp_StTypeRefCnt->MI_RefCount = 1 ; mp_StTypeRefCnt->MI_RefCount = 1 ;
new(&mp_StTypeRefCnt->MO_TypeData) TypeData(AR_TypeData); new(&mp_StTypeRefCnt->MO_TypeData) TypeData(AR_TypeData);
@ -4317,7 +4327,7 @@ namespace ZNsMain
ZtCObjNew(TTypeArg1& ArTTypeArg1, TTypeArg2& ArTTypeArg2) ZtCObjNew(TTypeArg1& ArTTypeArg1, TTypeArg2& ArTTypeArg2)
{ {
mp_StTypeRefCnt = (StTypeRefCnt*) mp_StTypeRefCnt = (StTypeRefCnt*)
this->ZCAllocator::NewMem(sizeof(StTypeRefCnt)); this->ZCAllocator::InitMem(sizeof(StTypeRefCnt));
mp_StTypeRefCnt->MI_RefCount = 1 ; mp_StTypeRefCnt->MI_RefCount = 1 ;
new(&mp_StTypeRefCnt->MO_TypeData) new(&mp_StTypeRefCnt->MO_TypeData)
@ -4336,7 +4346,7 @@ namespace ZNsMain
~ZtCObjNew() ~ZtCObjNew()
{ {
if(--mp_StTypeRefCnt->MI_RefCount <= 0) if(--mp_StTypeRefCnt->MI_RefCount <= 0)
this->ZCAllocator::DeleteMem(mp_StTypeRefCnt); this->ZCAllocator::FiniMem(mp_StTypeRefCnt);
}/* }/*
~ZtCObjNew()*/ ~ZtCObjNew()*/

View File

@ -728,7 +728,7 @@ namespace ZNsMain
~ZtCStringBase() ~ZtCStringBase()
{ {
if(ml_AllLen>0) this->DeleteMem(mpc_Data); if(ml_AllLen>0) this->FiniMem(mpc_Data);
}/* }/*
~ZtCStringBase()*/ ~ZtCStringBase()*/
@ -752,7 +752,7 @@ namespace ZNsMain
{ {
if(ml_AllLen>0) if(ml_AllLen>0)
{ {
this->DeleteMem(mpc_Data); this->FiniMem(mpc_Data);
ml_AllLen=0; ml_AllLen=0;
ml_UseLen=0; ml_UseLen=0;
@ -774,9 +774,9 @@ namespace ZNsMain
if(AB_DoKeepString==false) if(AB_DoKeepString==false)
{ {
this->DeleteMem(mpc_Data); this->FiniMem(mpc_Data);
mpc_Data =this->NewMem((VL_NewAllocSize+1)*sizeof(TypeChar)); mpc_Data =this->InitMem((VL_NewAllocSize+1)*sizeof(TypeChar));
ml_AllLen =VL_NewAllocSize ; ml_AllLen =VL_NewAllocSize ;
ml_UseLen =0 ; ml_UseLen =0 ;
mpc_Data[0]=0 ; mpc_Data[0]=0 ;
@ -787,7 +787,7 @@ namespace ZNsMain
// 문자열을 유지하는 경우 // 문자열을 유지하는 경우
TypeChar* VPC_NewChar = TypeChar* VPC_NewChar =
this->NewMem((VL_NewAllocSize+1)*sizeof(TypeChar)); this->InitMem((VL_NewAllocSize+1)*sizeof(TypeChar));
if(ml_UseLen>0) ::memcpy( if(ml_UseLen>0) ::memcpy(
VPC_NewChar, mpc_Data, ml_UseLen*sizeof(TypeChar)); VPC_NewChar, mpc_Data, ml_UseLen*sizeof(TypeChar));
@ -795,7 +795,7 @@ namespace ZNsMain
ml_AllLen =VL_NewAllocSize; ml_AllLen =VL_NewAllocSize;
VPC_NewChar[ml_UseLen]=0 ; VPC_NewChar[ml_UseLen]=0 ;
this->DeleteMem(mpc_Data); this->FiniMem(mpc_Data);
mpc_Data=VPC_NewChar; mpc_Data=VPC_NewChar;
}/* }/*
@ -833,7 +833,7 @@ namespace ZNsMain
{ {
if(ml_AllLen>0) if(ml_AllLen>0)
{ {
this->DeleteMem(mpc_Data) ; this->FiniMem(mpc_Data) ;
mpc_Data = 0 ; mpc_Data = 0 ;
ml_AllLen = ml_UseLen =0; ml_AllLen = ml_UseLen =0;
}/* }/*
@ -1537,7 +1537,7 @@ namespace ZNsMain
// Index1 번째 문자부터 VL_Index2 번째 문자까지 정수로 읽는다. // Index1 번째 문자부터 VL_Index2 번째 문자까지 정수로 읽는다.
TypeChar* VP_Char = this-> TypeChar* VP_Char = this->
NewMem(AL_Index2-AL_Index1+1+1/*Null Char*/); InitMem(AL_Index2-AL_Index1+1+1/*Null Char*/);
if(VP_Char==0) if(VP_Char==0)
{ {
@ -1556,7 +1556,7 @@ namespace ZNsMain
VP_Char[i] = 0 ; TypeLength VP_Char[i] = 0 ; TypeLength
VL_Return = ZNsMain::ZfAtoL(VP_Char); VL_Return = ZNsMain::ZfAtoL(VP_Char);
this->DeleteMem(VP_Char); return VL_Return; this->FiniMem(VP_Char); return VL_Return;
}/* }/*
TypeLength ReadLongFromIndex(TypeLength AL_Index1, TypeLength AL_Index2)*/ TypeLength ReadLongFromIndex(TypeLength AL_Index1, TypeLength AL_Index2)*/