summaryrefslogtreecommitdiffstats
path: root/private/windows/diamond/mem.h
blob: 6636c127e8b1c50a13419d74624991cc29a07123 (plain) (blame)
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
63
64
65
66
67
68
69
70
71
72
73
74
/***    mem.h - Definitions for Memory Manager
 *
 *      Microsoft Confidential
 *      Copyright (C) Microsoft Corporation 1993-1994
 *      All Rights Reserved.
 *
 *  The Memory Manager is a very thin layer on top of the native memory
 *  heap functions, allowing strong assertion checking and pointer
 *  validation in debug builds.
 *
 *  Author:
 *	Benjamin W. Slivka
 *
 *  History:
 *	10-Aug-1993 bens    Initial version
 *	11-Aug-1993 bens    Lift code from STOCK.EXE win app
 *	12-Aug-1993 bens    Improved comments
 *      18-Mar-1994 bens    strdup() now called _strdup(); renamed
 *      18-May-1994 bens    Allow turning off MemCheckHeap() in debug build
 *                              (it can really, really slow things down!)
 *
 *  Functions:
 *	MemAlloc  - Allocate memory block
 *	MemFree   - Free memory block
 *	MemStrDup - Duplicate string to new memory block
 *
 *  Functions available in ASSERT build:
 *      MemAssert       - Assert that pointer was allocated by MemAlloc
 *      MemCheckHeap    - Check entire memory heap
 *      MemGetSize      - Return allocated size of memory block
 *      MemSetCheckHeap - Control whether MemCheckHeap is done on every
 *                          every MemAlloc and MemFree!
 */

#ifndef INCLUDED_MEMORY
#define INCLUDED_MEMORY 1

#ifdef ASSERT

#define MemAlloc(cb)    MMAlloc(cb,__FILE__,__LINE__)
#define MemFree(pv)     MMFree(pv,__FILE__,__LINE__)
#define MemStrDup(pv)   MMStrDup(pv,__FILE__,__LINE__)

#define MemAssert(pv)   MMAssert(pv,__FILE__,__LINE__)
#define MemCheckHeap()  MMCheckHeap(__FILE__,__LINE__)
int	MemGetSize(void *pv);

void *MMAlloc(unsigned cb, char *pszFile, int iLine);
void  MMFree(void *pv, char *pszFile, int iLine);
void  MMAssert(void *pv, char *pszFile, int iLine);
void  MMCheckHeap(char *pszFile, int iLine);
char *MMStrDup(char *pv, char *pszFile, int iLine);
void  MemSetCheckHeap(BOOL f);

#else // !ASSERT

#include <malloc.h>     // Get malloc()/free()
#include <string.h>     // Get _strdup()


//** No Asserts

#define MemAlloc(cb)        malloc(cb)
#define MemFree(pv)         free(pv)
#define MemStrDup(pv)       _strdup(pv)

#define MemAssert(pv)
#define MemCheckHeap()
#define MemGetSize(pv)
#define MemSetCheckHeap(f)

#endif // !ASSERT

#endif // !INCLUDED_MEMORY