versadac  1
versadac - Scalable Recorder Firmware
uhh_heap.h
1 /******************************************************************************
2 FILE : uhh_heap.h
3 VERSION : $Id: uhh_heap.h 4938 2006-10-10 14:20:18Z martinto $
4 SYSTEM : Windows & VxWorks
5 DESCRIPTION : A static class to provide access to the appropriate heap.
6 ******************************************************************************/
7 
8 #ifndef __UHH_HEAP_H
9 #define __UHH_HEAP_H
10 
11 
12 #define DEBUG_HEAP 0
13 
14 extern "C"
15 {
16 #include "stdtypes.h"
17 }
18 
19 #ifdef WIN32
20 #include <malloc.h>
21 #if DEBUG_HEAP
22 #include <stdio.h>
23 static int s_nAlloc = 0;
24 #endif
25 #endif
26 
27 /******************************************************************************
28 CLASS : UhhHeap
29 DESCRIPTION : A C++ wrapper for the appropriate heap
30 ******************************************************************************/
31 class UhhHeap
32 {
33 #ifdef WIN32
34 
35  public:
36  static void *operator new(size_t size){return rm_malloc(size);}
37  static void operator delete(void *p){rm_free(p);}
38 
39 #if DEBUG_HEAP
40  static void *rm_realloc(void *p, size_t size)
41  {void *q = realloc(p,size); printf("R 0x%x -> 0x%x\n",p,q); return q;}
42  static void *rm_malloc(size_t size)
43  {void *p = malloc(size); printf("M %d 0x%x\n",s_nAlloc++,p); return p;}
44  static void rm_free(void *p)
45  {if(!p) return; printf("F %d 0x%08x\n",--s_nAlloc,p); free(p);}
46 #else
47  static void *rm_realloc(void *p, size_t size) {return realloc(p,size);}
48  static void *rm_malloc(size_t size) {return malloc(size);}
49  static void rm_free(void *p) {free(p);}
50 #endif
51 
52 #endif
53 };
54 
55 #endif
Definition: uhh_heap.h:31