<!DOCTYPE LINUXDOC SYSTEM>

<!-- This SGML file generated by cxref. -->
<!-- cxref program (c) Andrew M. Bishop 1995,96,97,98. -->

<article>

<title>Cross reference for memory.c of cxref.
<author>cxref

<sect>File memory.c
<bf>RCS Header: /home/amb/cxref/RCS/memory.c 1.12 1999/01/16 11:09:59 amb Exp </bf>
<p>

  C Cross Referencing &amp; Documentation tool. Version 1.5.
<newline>
  Memory management functions
<p>

<sect1>Included Files

<p>
<itemize>
<item><tt>#include &quot;autoconfig.h&quot;</tt>
</itemize>
<itemize>
<item><tt>#include &lt;stdio.h&gt;</tt>
</itemize>
<itemize>
<item><tt>#include &lt;stdlib.h&gt;</tt>
</itemize>
<itemize>
<item><tt>#include &lt;string.h&gt;</tt>
</itemize>
<itemize>
<item><tt>#include &lt;stdarg.h&gt;</tt>
</itemize>
<itemize>
<item><tt>#include &lt;memory.h&gt;</tt>
</itemize>
<itemize>
<item><tt>#include &quot;memory.h&quot;</tt>
</itemize>

<sect1>Preprocessor definitions

<p>
 The amount of debugging, non-zero for totals, 2 for logging, 4 for printing each call. 
<p>
<tt>#define DEBUG 0</tt><newline>
<p>
 The size of each of the heap allocations 
<p>
<tt>#define HEAP_INC 8192</tt><newline>
<p>
 The size of a string that is large enough to have it's own mallocation. 
<p>
<tt>#define SMALL_STRING 256</tt><newline>

<sect1>Typedef Heap

<p>
 A private memory heap is used to reduce the number of malloc calls that are made, the Heap type is a pointer to this. 
<p>
<tt>typedef struct _Heap* Heap</tt><newline>
<descrip>
<tag>See:</tag>
<itemize>
<item>Type struct _Heap
</itemize>
</descrip>

<sect1>Type struct _Heap

<p>
 A structure containing all of the information about the private heap in a linked list. 
<p>
<itemize>
<item><tt>struct _Heap</tt><newline>
<itemize>
<item><tt>{</tt><newline>
<item><tt>char* mem;      </tt> The memory that is private to the heap. <newline>
<item><tt>Heap next;      </tt> The next Heap structure. <newline>
<item><tt>}</tt><newline>
</itemize>
</itemize>

<sect1>Local Variables

<p>
<bf>first</bf><newline>
 Local variable to control the usage of the private heap;   the first segment of memory on the private heap. 
<p>
<tt>static Heap first</tt><newline>
<descrip>
<tag>Used in:</tag>
<itemize>
<item>TidyMemory()
<item>add_to_heap()
</itemize>
</descrip>
<p>
<bf>heap_left</bf><newline>
 the amount of space left in the current heap segment. 
<p>
<tt>static int heap_left</tt><newline>
<descrip>
<tag>Used in:</tag>
<itemize>
<item>TidyMemory()
<item>get_space()
</itemize>
</descrip>

<sect1>Global Function ConcatStrings()

<p>  A function to concatenate a number of strings.
<p>
<tt>char* ConcatStrings ( int n, char* s, ... )</tt><newline>
<descrip>
<tag><tt>char* ConcatStrings</tt></tag>
Returns the a pointer to the new string.
<tag><tt>int n</tt></tag>
The number of strings
<tag><tt>char* s</tt></tag>
The first string.
<tag><tt>...</tt></tag>
The other strings, 'n' including 's'.
</descrip>
  Any of the strings that are inputs can be NULL, in this case they are quietly ignored.
<p>
<descrip>
<tag>Prototyped in:</tag>
<itemize>
<item>memory.h
</itemize>
<tag>Calls:</tag>
<itemize>
<item>get_space()  :  memory.c
<item>strcat(), strlen()
</itemize>
<tag>Called by:</tag>
<itemize>
<item>CreateAppendix()  :  xref.c
<item>CrossReference()  :  xref.c
<item>CrossReferenceDelete()  :  xref.c
<item>SeenFileChange()  :  preproc.c
<item>SeenFuncIntComment()  :  func.c
<item>SeenFunctionDefinition()  :  func.c
<item>SeenInclude()  :  preproc.c
<item>SeenStructUnionComp()  :  type.c
<item>SplitComment()  :  comment.c
<item>WriteHTMLAppendix()  :  html.c
<item>WriteHTMLDocument()  :  html.c
<item>WriteHTMLFile()  :  html.c
<item>WriteHTMLFileDelete()  :  html.c
<item>WriteHTMLSource()  :  html.c
<item>WriteLatexAppendix()  :  latex.c
<item>WriteLatexDocument()  :  latex.c
<item>WriteLatexFile()  :  latex.c
<item>WriteLatexFileDelete()  :  latex.c
<item>WriteLatexTemplate()  :  latex.c
<item>WriteRTFAppendix()  :  rtf.c
<item>WriteRTFFile()  :  rtf.c
<item>WriteRTFFileDelete()  :  rtf.c
<item>WriteSGMLAppendix()  :  sgml.c
<item>WriteSGMLFile()  :  sgml.c
<item>WriteSGMLFileDelete()  :  sgml.c
<item>main()  :  cxref.c
<item>yyparse()  :  parse-yacc.c
</itemize>
</descrip>

<sect1>Global Function CopyString()

<p>  A function to copy a string on the local private memory heap.
<p>
<tt>char* CopyString ( char* x )</tt><newline>
<descrip>
<tag><tt>char* CopyString</tt></tag>
Returns the copy of the string.
<tag><tt>char* x</tt></tag>
The string to be copied.
</descrip>
<descrip>
<tag>Prototyped in:</tag>
<itemize>
<item>memory.h
</itemize>
<tag>Calls:</tag>
<itemize>
<item>get_space()  :  memory.c
<item>strcpy(), strlen()
</itemize>
<tag>Called by:</tag>
<itemize>
<item>ParseConfigFile()  :  cxref.c
<item>SplitComment()  :  comment.c
<item>yylex()  :  parse-lex.c
<item>yyparse()  :  parse-yacc.c
</itemize>
</descrip>

<sect1>Global Function PrintMemoryStatistics()

<p>  Prints out the number of mallocs / reallocs and frees.
<p>
<tt>void PrintMemoryStatistics ( void )</tt><newline>
<descrip>
<tag>Prototyped in:</tag>
<itemize>
<item>memory.h
</itemize>
<tag>Called by:</tag>
<itemize>
<item>main()  :  cxref.c
</itemize>
</descrip>

<sect1>Global Function SafeCalloc()

<p>  A replacement calloc() function.
<p>
<tt>void* SafeCalloc ( unsigned int n, unsigned int size, char* file, int line )</tt><newline>
<descrip>
<tag><tt>void* SafeCalloc</tt></tag>
Returns the address.
<tag><tt>unsigned int n</tt></tag>
The number of items to allocate.
<tag><tt>unsigned int size</tt></tag>
The size of the memory to allocate.
<tag><tt>char* file</tt></tag>
The file that the function is called from.
<tag><tt>int line</tt></tag>
The line number that the function is called from.
</descrip>
<descrip>
<tag>Prototyped in:</tag>
<itemize>
<item>memory.h
</itemize>
<tag>Calls:</tag>
<itemize>
<item>calloc(), printf()
</itemize>
<tag>Called by:</tag>
<itemize>
<item>NewDefineType()  :  preproc.c
<item>NewFile()  :  file.c
<item>NewFunctionType()  :  func.c
<item>NewIncludeType()  :  preproc.c
<item>NewStringList()  :  slist.c
<item>NewStringList2()  :  slist.c
<item>NewStructUnionType()  :  type.c
<item>NewTypedefType()  :  type.c
<item>NewVariableType()  :  var.c
</itemize>
</descrip>

<sect1>Global Function SafeFree()

<p>  A replacement free() function.
<p>
<tt>void SafeFree ( void* ptr, char* file, int line )</tt><newline>
<descrip>
<tag><tt>void* ptr</tt></tag>
The pointer that is to be freed up.
<tag><tt>char* file</tt></tag>
The file that the function is called from.
<tag><tt>int line</tt></tag>
The line number that the function is called from.
</descrip>
<descrip>
<tag>Prototyped in:</tag>
<itemize>
<item>memory.h
</itemize>
<tag>Calls:</tag>
<itemize>
<item>free(), printf()
</itemize>
<tag>Called by:</tag>
<itemize>
<item>DeleteComment()  :  comment.c
<item>DeleteDefineType()  :  preproc.c
<item>DeleteFile()  :  file.c
<item>DeleteFunctionType()  :  func.c
<item>DeleteIncludeType()  :  preproc.c
<item>DeleteStringList()  :  slist.c
<item>DeleteStringList2()  :  slist.c
<item>DeleteStructUnionType()  :  type.c
<item>DeleteTypedefType()  :  type.c
<item>DeleteVariableType()  :  var.c
<item>ParseConfigFile()  :  cxref.c
<item>ParseOptions()  :  cxref.c
<item>ResetParser()  :  parse-yacc.c
<item>ResetPreProcAnalyser()  :  preproc.c
<item>ResetVariableAnalyser()  :  var.c
<item>SeenFileChange()  :  preproc.c
<item>SeenFuncIntComment()  :  func.c
<item>SeenFunctionArg()  :  func.c
<item>SeenFunctionDefinition()  :  func.c
<item>SeenStructUnionComp()  :  type.c
<item>SeenVariableDefinition()  :  var.c
<item>SplitComment()  :  comment.c
<item>TidyMemory()  :  memory.c
<item>check_for_var_func()  :  xref.c
<item>fixup_extern_var()  :  xref.c
<item>html()  :  html.c
<item>latex()  :  latex.c
<item>main()  :  cxref.c
<item>rtf()  :  rtf.c
<item>sgml()  :  sgml.c
</itemize>
</descrip>

<sect1>Global Function SafeMalloc()

<p>  A replacement malloc() function.
<p>
<tt>void* SafeMalloc ( unsigned int size, char* file, int line )</tt><newline>
<descrip>
<tag><tt>void* SafeMalloc</tt></tag>
Returns the address.
<tag><tt>unsigned int size</tt></tag>
The size of the memory to allocate.
<tag><tt>char* file</tt></tag>
The file that the function is called from.
<tag><tt>int line</tt></tag>
The line number that the function is called from.
</descrip>
<descrip>
<tag>Prototyped in:</tag>
<itemize>
<item>memory.h
</itemize>
<tag>Calls:</tag>
<itemize>
<item>malloc(), printf()
</itemize>
<tag>Called by:</tag>
<itemize>
<item>AddToStringList()  :  slist.c
<item>AddToStringList2()  :  slist.c
<item>CopyStructUnion()  :  type.c
<item>ParseConfigFile()  :  cxref.c
<item>ParseOptions()  :  cxref.c
<item>SafeMallocString()  :  memory.c
<item>SeenComment()  :  comment.c
<item>SeenFileChange()  :  preproc.c
<item>SeenStructUnionComp()  :  type.c
<item>UpScope()  :  var.c
<item>add_to_heap()  :  memory.c
<item>html()  :  html.c
<item>latex()  :  latex.c
<item>main()  :  cxref.c
<item>push()  :  parse-yacc.c
<item>rtf()  :  rtf.c
<item>sgml()  :  sgml.c
</itemize>
</descrip>

<sect1>Global Function SafeMallocString()

<p>  A function to copy a string on the public global heap.
<p>
<tt>char* SafeMallocString ( char* x, char* file, int line )</tt><newline>
<descrip>
<tag><tt>char* SafeMallocString</tt></tag>
Returns the copy of the string.
<tag><tt>char* x</tt></tag>
The string to be copied.
<tag><tt>char* file</tt></tag>
The file that the function is called from.
<tag><tt>int line</tt></tag>
The line number that the function is called from.
</descrip>
<descrip>
<tag>Prototyped in:</tag>
<itemize>
<item>memory.h
</itemize>
<tag>Calls:</tag>
<itemize>
<item>SafeMalloc()  :  memory.c
<item>strcpy(), strlen()
</itemize>
<tag>Called by:</tag>
<itemize>
<item>AddToStringList()  :  slist.c
<item>AddToStringList2()  :  slist.c
<item>CopyStructUnion()  :  type.c
<item>NewDefineType()  :  preproc.c
<item>NewFile()  :  file.c
<item>NewFunctionType()  :  func.c
<item>NewIncludeType()  :  preproc.c
<item>NewStructUnionType()  :  type.c
<item>NewTypedefType()  :  type.c
<item>NewVariableType()  :  var.c
<item>ParseOptions()  :  cxref.c
<item>SeenDefine()  :  preproc.c
<item>SeenDefineComment()  :  preproc.c
<item>SeenDefineFuncArgComment()  :  preproc.c
<item>SeenDefineValue()  :  preproc.c
<item>SeenFileChange()  :  preproc.c
<item>SeenFileComment()  :  file.c
<item>SeenFuncIntComment()  :  func.c
<item>SeenFunctionArg()  :  func.c
<item>SeenFunctionDeclaration()  :  func.c
<item>SeenFunctionDefinition()  :  func.c
<item>SeenInclude()  :  preproc.c
<item>SeenIncludeComment()  :  preproc.c
<item>SeenStructUnionComp()  :  type.c
<item>SeenStructUnionStart()  :  type.c
<item>SeenTypedef()  :  type.c
<item>SeenVariableDefinition()  :  var.c
<item>SplitComment()  :  comment.c
<item>check_for_caller()  :  xref.c
<item>check_for_var()  :  xref.c
<item>check_for_var_func()  :  xref.c
<item>fixup_extern_var()  :  xref.c
<item>main()  :  cxref.c
</itemize>
</descrip>

<sect1>Global Function SafeRealloc()

<p>  A replacement realloc() function.
<p>
<tt>void* SafeRealloc ( void* ptr, unsigned int size, char* file, int line )</tt><newline>
<descrip>
<tag><tt>void* SafeRealloc</tt></tag>
Returns the address.
<tag><tt>void* ptr</tt></tag>
The old pointer.
<tag><tt>unsigned int size</tt></tag>
The size of the new memory to allocate.
<tag><tt>char* file</tt></tag>
The file that the function is called from.
<tag><tt>int line</tt></tag>
The line number that the function is called from.
</descrip>
<descrip>
<tag>Prototyped in:</tag>
<itemize>
<item>memory.h
</itemize>
<tag>Calls:</tag>
<itemize>
<item>printf(), realloc()
</itemize>
<tag>Called by:</tag>
<itemize>
<item>AddToStringList()  :  slist.c
<item>AddToStringList2()  :  slist.c
<item>ParseConfigFile()  :  cxref.c
<item>ParseOptions()  :  cxref.c
<item>SeenComment()  :  comment.c
<item>SeenFileChange()  :  preproc.c
<item>SeenStructUnionComp()  :  type.c
<item>SetCurrentComment()  :  comment.c
<item>UpScope()  :  var.c
<item>html()  :  html.c
<item>latex()  :  latex.c
<item>main()  :  cxref.c
<item>push()  :  parse-yacc.c
<item>rtf()  :  rtf.c
<item>sgml()  :  sgml.c
</itemize>
</descrip>

<sect1>Global Function TidyMemory()

<p>  Tidies up the local heap of memory.
<p>
<tt>void TidyMemory ( void )</tt><newline>
<descrip>
<tag>Prototyped in:</tag>
<itemize>
<item>memory.h
</itemize>
<tag>Calls:</tag>
<itemize>
<item>SafeFree()  :  memory.c
</itemize>
<tag>Called by:</tag>
<itemize>
<item>main()  :  cxref.c
</itemize>
<tag>References Variables:</tag>
<itemize>
<item>first  :  memory.c
<item>heap_left  :  memory.c
</itemize>
</descrip>

<sect1>Local Function add_to_heap()

<p>  Add some bytes to the privately maintained memory heap.
<p>
<tt>static Heap add_to_heap ( unsigned int l )</tt><newline>
<descrip>
<tag><tt>Heap add_to_heap</tt></tag>
Returns a pointer to the required memory.
<tag><tt>unsigned int l</tt></tag>
The size of the memory that is required.
</descrip>
<descrip>
<tag>Prototyped in:</tag>
<itemize>
<item>memory.c
</itemize>
<tag>Calls:</tag>
<itemize>
<item>SafeMalloc()  :  memory.c
</itemize>
<tag>Called by:</tag>
<itemize>
<item>get_space()  :  memory.c
</itemize>
<tag>References Variables:</tag>
<itemize>
<item>first  :  memory.c
</itemize>
</descrip>

<sect1>Local Function get_space()

<p>  A function to get some memory for a string, allocate a new heap structure if needed.
<p>
<tt>static char* get_space ( unsigned int l )</tt><newline>
<descrip>
<tag><tt>char* get_space</tt></tag>
Returns a pointer to enough space.
<tag><tt>unsigned int l</tt></tag>
The amount of space that is needed.
</descrip>
<descrip>
<tag>Prototyped in:</tag>
<itemize>
<item>memory.c
</itemize>
<tag>Calls:</tag>
<itemize>
<item>add_to_heap()  :  memory.c
</itemize>
<tag>Called by:</tag>
<itemize>
<item>ConcatStrings()  :  memory.c
<item>CopyString()  :  memory.c
</itemize>
<tag>References Variables:</tag>
<itemize>
<item>heap_left  :  memory.c
</itemize>
</descrip>

</article>
