ARoutine Analyzer Source File Analysis - objalloc.c7

objalloc.c Source Code

LGo to: Contents; Previous section; Beginning of section; Next file in section; Previous file in section.

Q

Routines In This File (Alphabetical)



 Line Name
----- ----'  148 free_str&  105 new_str(   27 obj_alloc'   75 obj_free-  204 trace_free_obj,  174 trace_new_obj


BEGINNING OF FILE


V     1: /****************************************************************************/     2: /*									    */8     3: /*  FACILITY:	Generic Support Library					    */     4: /*									    */7     5: /*  MODULE:	Object Memory Management 				    */     6: /*									    */O     7: /*  AUTHOR:	Steve Branam, Network Product Support Group, Digital	    */>     8: /*		Equipment Corporation, Littleton, MA, USA.		    */     9: /*									    */V    10: /*  DESCRIPTION: This module contains routines to support memory allocation */U    11: /*  and deallocation of application objects from the heap. It supports	    */U    12: /*  string objects directly, and provides routines to be used by other	    */V    13: /*  object types, both to do the actual memory management, and for tracing  *//    14: /*  the activity to stdout.						    */    15: /*									    */*    16: /*  REVISION HISTORY:							    */    17: /*									    */7    18: /*  V0.1-00 24-AUG-1994 Steve Branam					    */    19: /*									    */(    20: /*	Original version.						    */    21: /*									    */V    22: /****************************************************************************/    23:     24: #include "objalloc.h"    25: V    26: /*************************************************************************++*/

bROUTINE obj_alloc. Go to: mNext routine in file; Routines in this file.



    27: char *obj_alloc(V    28: /* Allocates and clears memory for an object, warning if the allocation	    */U    29: /* exceeds the expected limit for the object, or the available memory.	    */    30:     31:     long    vNBytes,,    32: 	    /* (READ, BY VAL):  					    */6    33: 	    /* Number of bytes to allocate.				    */    34:     35:     long    vMaxBytes,,    36: 	    /* (READ, BY VAL):  					    */O    37: 	    /* Maximum number of bytes for this type of object. If vNBytes  */O    38: 	    /* is larger than vMaxBytes, a warning will be issued, since    */O    39: 	    /* this indicates that some assumption about the size of an	    */M    40: 	    /* object has been violated, but the object will still be	    */&    41: 	    /* allocated.						    */    42:     43:     char    *aTypeName-    44: 	    /* (READ, BY ADDR):  					    */3    45: 	    /* Object type name string.					    */    46: P    47: )	/* Returns ptr to allocated object, or NULL if the memory could not */%    48: 	/* be allocated.						    */O    49: 	/*****************************************************************--*/    50: 	    51: {B    52:     char    *ptr;			    /* Ptr to allocated memory.	    */    53: )    54:     if (vNBytes > vMaxBytes) {P    55: 	printf("WARNING: Alloc of %ld bytes for %s exceeds max of %ld bytes\n",,    56: 	    vNBytes, aTypeName, vMaxBytes);
    57:     }5    58:     if ((ptr = calloc(1, vNBytes)) == NULL) {G    59: 	printf("WARNING: Alloc of %ld bytes for %s failed\n", vNBytes,    60: 	    aTypeName);
    61:     }    62:     else {    63: 	inc_nobjects();     64: 	inc_nobjbytes(vNBytes);#    65: 	if (trace_mem_enabled()) {    66: 	    printf(K    67: 	"TRACE: Alloc %ld bytes for %s @ %lxh, %ld objects (%ld bytes)\n",B    68: 		vNBytes, aTypeName, ptr, num_objects(), num_objbytes());
    69: 	}
    70:     }    71:     return ptr;	    72: }
GEND obj_alloc. Go to: Beginning of routine.





    73: V    74: /*************************************************************************++*/

aROUTINE obj_free. Go to: mNext routine in file; Routines in this file.



    75: char *obj_free(:    76: /* Frees memory allocated for an object.				    */    77:     78:     void    *aObject,/    79: 	    /* (DELETE, BY ADDR):  					    */0    80: 	    /* Object to be deleted.					    */    81:     82:     long    vNBytes,,    83: 	    /* (READ, BY VAL):  					    */2    84: 	    /* Size of object to free.					    */    85:     86:     char    *aTypeName-    87: 	    /* (READ, BY ADDR):  					    */3    88: 	    /* Object type name string.					    */    89: *    90: )	/* Returns NULL ptr.						    */O    91: 	/*****************************************************************--*/    92: 	    93: {    94:     dec_nobjects();#    95:     dec_nobjbytes(vNBytes);&    96:     if (trace_mem_enabled()) {Q    97: 	printf("TRACE: Free %ld bytes for %s @ %lxh, %ld objects (%ld bytes)\n",I    98: 	    vNBytes, aTypeName, aObject, num_objects(), num_objbytes());
    99:     }   100:     free(aObject);   101:     return NULL;	   102: }
FEND obj_free. Go to: Beginning of routine.





   103: V   104: /*************************************************************************++*/

`ROUTINE new_str. Go to: mNext routine in file; Routines in this file.



   105: char *new_str(?   106: /* Allocates and initializes a string object.				    */   107:    108:     char    *aStr,-   109: 	    /* (READ, BY ADDR):  					    */O   110: 	    /* String value. The memory will be allocated just large enough *//   111: 	    /* to hold this string.					    */   112:    113:     long    vMaxBytes,+   114: 	    /* (READ, BY VAL):						    */O   115: 	    /* Maximum number of bytes for this type of object. If length   */L   116: 	    /* of aStr is larger than vMaxBytes (which is assumed to	    */M   117: 	    /* exclude the string null terminator), a warning will be	    */O   118: 	    /* issued, since this indicates that some assumption about the  */O   119: 	    /* size of an object has been violated, but the object will	    */.   120: 	    /* still be allocated.					    */   121:    122:     char    *aTypeName-   123: 	    /* (READ, BY ADDR):  					    */3   124: 	    /* Object type name string.					    */   125: P   126: )	/* Returns ptr to allocated object, or NULL if the memory could not */%   127: 	/* be allocated.						    */O   128: 	/*****************************************************************--*/   129: 	   130: {=   131:     int	    length;			    /* Length of string.	    */B   132:     char    *ptr;			    /* Ptr to allocated memory.	    */   133: &   134:     length = strlen(aStr) + 1;N   135:     if ((ptr = obj_alloc(length, vMaxBytes + 1, aTypeName)) != NULL) {   136: 	inc_nstrings();   137: 	strcpy(ptr, aStr);#   138: 	if (trace_str_enabled()) {G   139: 	    printf("TRACE: Alloc %s string \"%s\"\n", aTypeName, ptr);L   140: 	    printf("       @ %lxh, %ld objects (%ld bytes), %ld strings\n",=   141: 		ptr, num_objects(), num_objbytes(), num_strings());   142:     	}
   143:     }   144:     return ptr;	   145: }
EEND new_str. Go to: Beginning of routine.





=   146: V   147: /*************************************************************************++*/

aROUTINE free_str. Go to: imNext routine in file; Routines in this file.

s

.   148: char *free_str(f-   149: /* Frees a string object.						    */n   150:    151:     char    *aStr,/   152: 	    /* (DELETE, BY ADDR):  					    */-+   153: 	    /* String to free.						    */   154:    155:     char    *aTypeName-   156: 	    /* (READ, BY ADDR):  					    */A3   157: 	    /* Object type name string.					    */0   158: *   159: )	/* Returns NULL ptr.						    */O   160: 	/*****************************************************************--*/    161: 	   162: {*   163:     dec_nstrings();*&   164:     if (trace_str_enabled()) {C   165: 	printf("TRACE: Free %s string \"%s\"\n", aTypeName, aStr);	N   166: 	printf("       @ %lxh freed, %ld objects (%ld bytes), %ld strings\n",A   167: 	    aStr, num_objects(), num_objbytes(), num_strings());v
   168:     }r8   169:     obj_free(aStr, strlen(aStr) + 1, aTypeName);   170:     return NULL;	   171: }.
FEND free_str. Go to: Beginning of routine.





t   172: V   173: /*************************************************************************++*/

fROUTINE trace_new_obj. Go to: mNext routine in file; Routines in this file.

t

	   174: void trace_new_obj(	D   175: /* Prints a trace message for an object allocation.			    */   176:    177:     void    *aObject,9-   178: 	    /* (READ, BY ADDR):  					    */ /   179: 	    /* Object to be traced.					    */   180:    181:     char    *aTypeName,*-   182: 	    /* (READ, BY ADDR):  					    */*3   183: 	    /* Object type name string.					    */b   184:    185:     char    *aName,*-   186: 	    /* (READ, BY ADDR):  					    */*6   187: 	    /* Object instance name string.				    */   188:    189:     long    vNObjectsl,   190: 	    /* (READ, BY VAL):  					    */O   191: 	    /* Total number of objects of this type allocated after this    */ -   192: 	    /* one was allocated.					    */l   193: .   194: )	/* No return value.      					    */O   195: 	/*****************************************************************--*/    196: 	   197: {b=   198:     printf("TRACE: Alloc %s %s\n", aTypeName, aName); G   199:     printf("       @ %lxh, %ld objects (%ld bytes), %ld %ss\n", G   200: 	aObject, num_objects(), num_objbytes(), vNObjects, aTypeName); 	   201: }A
KEND trace_new_obj. Go to: Beginning of routine.

j



e   202: V   203: /*************************************************************************++*/

gROUTINE trace_free_obj. Go to: umNext routine in file; Routines in this file.

e

    204: void trace_free_obj(F   205: /* Prints a trace message for an object deallocation.			    */   206:    207:     void    *aObject,a-   208: 	    /* (READ, BY ADDR):  					    *//   209: 	    /* Object to be traced.					    *//   210:    211:     char    *aTypeName,*-   212: 	    /* (READ, BY ADDR):  					    */3   213: 	    /* Object type name string.					    */    214:    215:     char    *aName,f-   216: 	    /* (READ, BY ADDR):  					    */W6   217: 	    /* Object instance name string.				    */   218:    219:     long    vNObjectsv,   220: 	    /* (READ, BY VAL):  					    */O   221: 	    /* Total number of objects of this type allocated before this   */s)   222: 	    /* one is freed.						    */a   223: .   224: )	/* No return value.      					    */O   225: 	/*****************************************************************--*/)   226: 	   227: {i<   228:     printf("TRACE: Free %s %s\n", aTypeName, aName);G   229:     printf("       @ %lxh, %ld objects (%ld bytes), %ld %ss\n",uK   230: 	aObject, num_objects(), num_objbytes(), vNObjects - 1, aTypeName); 	   231: }
LEND trace_free_obj. Go to: Beginning of routine.





    232: 
END OF FILE* TOTAL: 6 routines, 33 Avg Length

LGo to: Contents; Previous section; Beginning of section; Next file in section; Previous file in section.