diff --git a/ccstruct/rejctmap.cpp b/ccstruct/rejctmap.cpp index 2123230e52d1284b037e927a803831a8f300eb83..6870ce9a3835c84b42127aec784188242b2fae6a 100644 --- a/ccstruct/rejctmap.cpp +++ b/ccstruct/rejctmap.cpp @@ -265,9 +265,9 @@ void REJ::full_print(FILE *fp) { } -//The REJMAP class has been hacked to use alloc_struct instead of new []. +//The REJMAP class has been hacked to use malloc instead of new []. //This is to reduce memory fragmentation only as it is rather kludgy. -// alloc_struct by-passes the call to the constructor of REJ on each +// malloc by-passes the call to the constructor of REJ on each // array element. Although the constructor is empty, the BITS16 members // do have a constructor which sets all the flags to 0. The memset // replaces this functionality. @@ -281,7 +281,7 @@ REJMAP::REJMAP( //classwise copy len = source.length (); if (len > 0) { - ptr = (REJ *) alloc_struct (len * sizeof (REJ), "REJ"); + ptr = (REJ *) malloc(len * sizeof (REJ)); to = ptr; for (i = 0; i < len; i++) { *to = *from; @@ -317,12 +317,10 @@ const REJMAP & source //from this void REJMAP::initialise( //Redefine map inT16 length) { - if (ptr != NULL) - free_struct (ptr, len * sizeof (REJ), "REJ"); + free(ptr); len = length; if (len > 0) - ptr = (REJ *) memset (alloc_struct (len * sizeof (REJ), "REJ"), - 0, len * sizeof (REJ)); + ptr = (REJ *) calloc(len, sizeof(REJ)); else ptr = NULL; } @@ -374,8 +372,7 @@ void REJMAP::remove_pos( //Cut out an element len--; if (len > 0) - new_ptr = (REJ *) memset (alloc_struct (len * sizeof (REJ), "REJ"), - 0, len * sizeof (REJ)); + new_ptr = (REJ *) malloc(len * sizeof(REJ)); else new_ptr = NULL; @@ -386,7 +383,7 @@ void REJMAP::remove_pos( //Cut out an element new_ptr[pos] = ptr[pos + 1]; //copy post pos //delete old map - free_struct (ptr, (len + 1) * sizeof (REJ), "REJ"); + free(ptr); ptr = new_ptr; } diff --git a/ccstruct/rejctmap.h b/ccstruct/rejctmap.h index 009ba58a7840004bc87153befb19ac84e1b41845..84b5009b34299059d0d4eb36f641c4f3dbd3d9c8 100644 --- a/ccstruct/rejctmap.h +++ b/ccstruct/rejctmap.h @@ -219,8 +219,7 @@ class REJMAP const REJMAP & source); //from this ~REJMAP () { //destructor - if (ptr != NULL) - free_struct (ptr, len * sizeof (REJ), "REJ"); + free(ptr); } void initialise( //Redefine map diff --git a/ccutil/memry.cpp b/ccutil/memry.cpp index 925efda8118a403b1f68a59660b507d9eeb9f7dc..63094c1be20a1115de00c3e15f17486106bc54af 100644 --- a/ccutil/memry.cpp +++ b/ccutil/memry.cpp @@ -36,14 +36,6 @@ void free_string(char *string) { free(string); } -void* alloc_struct(inT32 count, const char *) { - return malloc(count); -} - -void free_struct(void *deadstruct, inT32, const char *) { - free(deadstruct); -} - void *alloc_mem(inT32 count) { return malloc(static_cast(count)); } diff --git a/ccutil/memry.h b/ccutil/memry.h index 66e146e609a4a7f5ec2ad8ba907fbdd94f082be4..0ec275718e8b3a0b2407ff0e8ee826f60c080945 100644 --- a/ccutil/memry.h +++ b/ccutil/memry.h @@ -27,10 +27,6 @@ extern char *alloc_string(inT32 count); // free a string. extern void free_string(char *string); -// allocate memory -extern void *alloc_struct(inT32 count, const char *name = NULL); -// free a structure. -extern void free_struct(void *deadstruct, inT32, const char *name = NULL); // get some memory extern void *alloc_mem(inT32 count); // get some memory initialized to 0. diff --git a/classify/adaptive.cpp b/classify/adaptive.cpp index 9d00a51cb5f6acf1e042251717be6a0260e522a0..039373c58123e6364a1909c2948c730d9556bc6a 100644 --- a/classify/adaptive.cpp +++ b/classify/adaptive.cpp @@ -84,7 +84,7 @@ void FreeTempConfig(TEMP_CONFIG Config) { destroy_nodes (Config->ContextsSeen, memfree); FreeBitVector (Config->Protos); - free_struct (Config, sizeof (TEMP_CONFIG_STRUCT), "TEMP_CONFIG_STRUCT"); + free(Config); } /* FreeTempConfig */ @@ -92,13 +92,13 @@ void FreeTempConfig(TEMP_CONFIG Config) { void FreeTempProto(void *arg) { PROTO proto = (PROTO) arg; - free_struct (proto, sizeof (TEMP_PROTO_STRUCT), "TEMP_PROTO_STRUCT"); + free(proto); } void FreePermConfig(PERM_CONFIG Config) { assert(Config != NULL); delete [] Config->Ambigs; - free_struct(Config, sizeof(PERM_CONFIG_STRUCT), "PERM_CONFIG_STRUCT"); + free(Config); } /*---------------------------------------------------------------------------*/ @@ -223,12 +223,9 @@ void free_adapted_templates(ADAPT_TEMPLATES templates) { * @note History: Thu Mar 14 13:28:21 1991, DSJ, Created. */ TEMP_CONFIG NewTempConfig(int MaxProtoId, int FontinfoId) { - TEMP_CONFIG Config; int NumProtos = MaxProtoId + 1; - Config = - (TEMP_CONFIG) alloc_struct (sizeof (TEMP_CONFIG_STRUCT), - "TEMP_CONFIG_STRUCT"); + TEMP_CONFIG Config = (TEMP_CONFIG) malloc(sizeof(TEMP_CONFIG_STRUCT)); Config->Protos = NewBitVector (NumProtos); Config->NumTimesSeen = 1; @@ -254,8 +251,7 @@ TEMP_CONFIG NewTempConfig(int MaxProtoId, int FontinfoId) { * @note History: Thu Mar 14 13:31:31 1991, DSJ, Created. */ TEMP_PROTO NewTempProto() { - return ((TEMP_PROTO) - alloc_struct (sizeof (TEMP_PROTO_STRUCT), "TEMP_PROTO_STRUCT")); + return (TEMP_PROTO) malloc(sizeof(TEMP_PROTO_STRUCT)); } /* NewTempProto */ @@ -317,7 +313,6 @@ ADAPT_CLASS ReadAdaptedClass(TFile *fp) { int NumConfigs; int i; ADAPT_CLASS Class; - TEMP_PROTO TempProto; /* first read high level adapted class structure */ Class = (ADAPT_CLASS) Emalloc (sizeof (ADAPT_CLASS_STRUCT)); @@ -335,9 +330,7 @@ ADAPT_CLASS ReadAdaptedClass(TFile *fp) { fp->FRead(&NumTempProtos, sizeof(int), 1); Class->TempProtos = NIL_LIST; for (i = 0; i < NumTempProtos; i++) { - TempProto = - (TEMP_PROTO) alloc_struct (sizeof (TEMP_PROTO_STRUCT), - "TEMP_PROTO_STRUCT"); + TEMP_PROTO TempProto = (TEMP_PROTO) malloc(sizeof(TEMP_PROTO_STRUCT)); fp->FRead(TempProto, sizeof(TEMP_PROTO_STRUCT), 1); Class->TempProtos = push_last (Class->TempProtos, TempProto); } @@ -402,8 +395,7 @@ ADAPT_TEMPLATES Classify::ReadAdaptedTemplates(TFile *fp) { * @note History: Tue Mar 19 14:25:26 1991, DSJ, Created. */ PERM_CONFIG ReadPermConfig(TFile *fp) { - PERM_CONFIG Config = (PERM_CONFIG) alloc_struct(sizeof(PERM_CONFIG_STRUCT), - "PERM_CONFIG_STRUCT"); + PERM_CONFIG Config = (PERM_CONFIG) malloc(sizeof(PERM_CONFIG_STRUCT)); uinT8 NumAmbigs; fp->FRead(&NumAmbigs, sizeof(uinT8), 1); Config->Ambigs = new UNICHAR_ID[NumAmbigs + 1]; @@ -429,11 +421,7 @@ PERM_CONFIG ReadPermConfig(TFile *fp) { * @note History: Tue Mar 19 14:29:59 1991, DSJ, Created. */ TEMP_CONFIG ReadTempConfig(TFile *fp) { - TEMP_CONFIG Config; - - Config = - (TEMP_CONFIG) alloc_struct (sizeof (TEMP_CONFIG_STRUCT), - "TEMP_CONFIG_STRUCT"); + TEMP_CONFIG Config = (TEMP_CONFIG) malloc(sizeof(TEMP_CONFIG_STRUCT)); fp->FRead(Config, sizeof(TEMP_CONFIG_STRUCT), 1); Config->Protos = NewBitVector (Config->ProtoVectorSize * BITSINLONG); diff --git a/classify/adaptmatch.cpp b/classify/adaptmatch.cpp index 36a8ac14638a53f8850c752ad75deb596d3b84ae..8d69e6d1032fd4525e238a84d1a4f7fc6585d541 100644 --- a/classify/adaptmatch.cpp +++ b/classify/adaptmatch.cpp @@ -1980,8 +1980,7 @@ void Classify::MakePermanent(ADAPT_TEMPLATES Templates, // Initialize permanent config. Ambigs = GetAmbiguities(Blob, ClassId); - PERM_CONFIG Perm = (PERM_CONFIG) alloc_struct(sizeof(PERM_CONFIG_STRUCT), - "PERM_CONFIG_STRUCT"); + PERM_CONFIG Perm = (PERM_CONFIG) malloc(sizeof(PERM_CONFIG_STRUCT)); Perm->Ambigs = Ambigs; Perm->FontinfoId = Config->FontinfoId; diff --git a/classify/mfoutline.cpp b/classify/mfoutline.cpp index 59593a8523f817f68e20287038acfc88a10677e9..3bd0916eddcb24677a512172a19700168f6eb4f0 100644 --- a/classify/mfoutline.cpp +++ b/classify/mfoutline.cpp @@ -160,7 +160,7 @@ void FreeMFOutline(void *arg) { //MFOUTLINE Outline Start = list_rest (Outline); set_rest(Outline, NIL_LIST); while (Start != NULL) { - free_struct (first_node (Start), sizeof (MFEDGEPT), "MFEDGEPT"); + free(first_node(Start)); Start = pop (Start); } @@ -219,7 +219,7 @@ void MarkDirectionChanges(MFOUTLINE Outline) { /*---------------------------------------------------------------------------*/ /** Return a new edge point for a micro-feature outline. */ MFEDGEPT *NewEdgePoint() { - return ((MFEDGEPT *) alloc_struct(sizeof(MFEDGEPT), "MFEDGEPT")); + return (MFEDGEPT *) malloc(sizeof(MFEDGEPT)); } diff --git a/classify/ocrfeatures.cpp b/classify/ocrfeatures.cpp index 7df8135048d6f305f581ee58f3d932c0249f66dc..dae1d6763c176855a5aeba409ec8ce848eaeff88 100644 --- a/classify/ocrfeatures.cpp +++ b/classify/ocrfeatures.cpp @@ -58,12 +58,7 @@ BOOL8 AddFeature(FEATURE_SET FeatureSet, FEATURE Feature) { * @note History: Mon May 21 13:33:27 1990, DSJ, Created. */ void FreeFeature(FEATURE Feature) { - if (Feature) { - free_struct (Feature, sizeof (FEATURE_STRUCT) - + sizeof (FLOAT32) * (Feature->Type->NumParams - 1), - "sizeof(FEATURE_STRUCT)+sizeof(FLOAT32)*(NumParamsIn(Feature)-1)"); - } - + free(Feature); } /* FreeFeature */ /** @@ -94,10 +89,9 @@ void FreeFeatureSet(FEATURE_SET FeatureSet) { FEATURE NewFeature(const FEATURE_DESC_STRUCT* FeatureDesc) { FEATURE Feature; - Feature = (FEATURE) alloc_struct (sizeof (FEATURE_STRUCT) + + Feature = (FEATURE) malloc(sizeof(FEATURE_STRUCT) + (FeatureDesc->NumParams - 1) * - sizeof (FLOAT32), - "sizeof(FEATURE_STRUCT)+sizeof(FLOAT32)*(NumParamsIn(Feature)-1)"); + sizeof (FLOAT32)); Feature->Type = FeatureDesc; return (Feature);