File: memory.h

package info (click to toggle)
cxref 1.4-5
  • links: PTS
  • area: main
  • in suites: slink
  • size: 1,500 kB
  • ctags: 1,526
  • sloc: ansic: 16,881; sh: 4,710; yacc: 1,913; lex: 375; lisp: 256; makefile: 249; perl: 78
file content (62 lines) | stat: -rw-r--r-- 2,382 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/***************************************
  $Header: /home/amb/cxref/RCS/memory.h 1.7 1996/02/24 14:53:30 amb Exp $

  C Cross Referencing & Documentation tool. Version 1.0

  Memory management functions
  ******************/ /******************
  Written by Andrew M. Bishop

  This file Copyright 1995,96 Andrew M. Bishop
  It may be distributed under the GNU Public License, version 2, or
  any higher version.  See section COPYING of the GNU Public license
  for conditions under which this file may be redistributed.
  ***************************************/


#ifndef MEMORY_H
#define MEMORY_H   /*+ To stop multiple inclusions. +*/

/*+ malloc(), calloc(), realloc() and free() replacements +*/

#define Malloc(s)    SafeMalloc (  s,__FILE__,__LINE__)
#define Calloc(n,s)  SafeCalloc (n,s,__FILE__,__LINE__)
#define Realloc(p,s) SafeRealloc(p,s,__FILE__,__LINE__)
#define Free(p)      SafeFree   (p  ,__FILE__,__LINE__)

void* SafeMalloc(unsigned int size,char* file,int line);
void* SafeCalloc(unsigned int n,unsigned int size,char* file,int line);
void* SafeRealloc(void* ptr,unsigned int size,char* file,int line);
void  SafeFree(void* ptr,char* file,int line);

/*+ String manipulation functions on public heap +*/

#define MallocString(p) SafeMallocString (p,__FILE__,__LINE__)

char* SafeMallocString(char* x,char* file,int line);

/* String manipulation functions on private memory heap */

char* CopyString(char* x);
char* ConcatStrings(int n,char* s, ...);
void TidyMemory(void);

/* Internal Functions */

void PrintMemoryStatistics(void);

/* Memory handling concepts *

   0) Memory that is private only lasts for the period of parsing the file (including cross-referencing).
   1) All storage for File, Function etc. data types is to be public (permanent).
   2) Data used during parsing is to be private.
   3) Copying of strings is only to be performed if needed, all of the following use the private heap.
      a) Lex code passes constant values to Yacc code where possible.
      b) Lex code is to pass copies of strings to Yacc code since it disappears otherwise.
      c) Yacc code concatanates strings for internal manipulation.
      d) Lex passes pointers (not copies) to comment.c where private copies are made.
   4) Comments from comment.c are passed as private data, the receiver must Malloc a copy of them.

 * Memory handling concepts */

#endif