Browse Source

Fixed memory test builds.

Thomas Buck 10 years ago
parent
commit
c0f771c2bd
2 changed files with 86 additions and 84 deletions
  1. 68
    70
      src/memeory_test.cpp
  2. 18
    14
      src/memeory_test.h

+ 68
- 70
src/memeory_test.cpp View File

1
 /* -*- Mode: C++; tab-width: 3; indent-tabs-mode: t; c-basic-offset: 3 -*- */
1
 /* -*- Mode: C++; tab-width: 3; indent-tabs-mode: t; c-basic-offset: 3 -*- */
2
 /*================================================================
2
 /*================================================================
3
- * 
3
+ *
4
  * Project : MTK
4
  * Project : MTK
5
  * Author  : Terry 'Mongoose' Hendrix II
5
  * Author  : Terry 'Mongoose' Hendrix II
6
  * Website : http://www.westga.edu/~stu7440/
6
  * Website : http://www.westga.edu/~stu7440/
10
  * Comments: Memory testing tool kit
10
  * Comments: Memory testing tool kit
11
  *
11
  *
12
  *
12
  *
13
- *           This file was generated using Mongoose's C++ 
13
+ *           This file was generated using Mongoose's C++
14
  *           template generator script.  <stu7440@westga.edu>
14
  *           template generator script.  <stu7440@westga.edu>
15
- * 
16
- *-- History ------------------------------------------------- 
15
+ *
16
+ *-- History -------------------------------------------------
17
  *
17
  *
18
  * 2002.03.27:
18
  * 2002.03.27:
19
  * Mongoose - Created
19
  * Mongoose - Created
235
 	if (tree->parent)  // Not root
235
 	if (tree->parent)  // Not root
236
 	{
236
 	{
237
 		uncle = (tree->parent)->left;
237
 		uncle = (tree->parent)->left;
238
-		
238
+
239
 		// Mix up at hosptial, switch parent's children!
239
 		// Mix up at hosptial, switch parent's children!
240
 		if (tree == uncle)
240
 		if (tree == uncle)
241
 		{
241
 		{
286
 
286
 
287
 	if (left)
287
 	if (left)
288
 	{
288
 	{
289
-		left->parent = tree->parent;  
289
+		left->parent = tree->parent;
290
 	}
290
 	}
291
 
291
 
292
 	parent = tree->parent;
292
 	parent = tree->parent;
330
 
330
 
331
 	tree = *root;
331
 	tree = *root;
332
 	prev = 0x0;
332
 	prev = 0x0;
333
-		
333
+
334
 	do
334
 	do
335
 	{
335
 	{
336
 		prev = tree;
336
 		prev = tree;
359
 	else
359
 	else
360
 	{
360
 	{
361
 		prev->right = tree_new(data, key);
361
 		prev->right = tree_new(data, key);
362
-		tree = prev->right;		
362
+		tree = prev->right;
363
 	}
363
 	}
364
 
364
 
365
 	tree->parent = prev;
365
 	tree->parent = prev;
372
 		// Parent is a left child
372
 		// Parent is a left child
373
 		if (tree->parent == tree->parent->parent->left)
373
 		if (tree->parent == tree->parent->parent->left)
374
 		{
374
 		{
375
-			// Tree's right uncle 
375
+			// Tree's right uncle
376
 			uncle = tree->parent->parent->right;
376
 			uncle = tree->parent->parent->right;
377
-			
377
+
378
 			// Parent and Uncle are RED
378
 			// Parent and Uncle are RED
379
          if ((uncle) && (uncle->color == RB_RED))
379
          if ((uncle) && (uncle->color == RB_RED))
380
-			{ 
380
+			{
381
            // Change Parent and Uncle to BLACK, make grandparent RED
381
            // Change Parent and Uncle to BLACK, make grandparent RED
382
            tree->parent->color = RB_BLACK;
382
            tree->parent->color = RB_BLACK;
383
-           uncle->color = RB_BLACK; 
383
+           uncle->color = RB_BLACK;
384
            tree->parent->parent->color = RB_RED;
384
            tree->parent->parent->color = RB_RED;
385
 
385
 
386
-			  // Continue from grandparent 
386
+			  // Continue from grandparent
387
            tree = tree->parent->parent;
387
            tree = tree->parent->parent;
388
-         } 
388
+         }
389
          else  // Parent is RED and Uncle is BLACK
389
          else  // Parent is RED and Uncle is BLACK
390
 			{
390
 			{
391
-				// Tree is a right child 
391
+				// Tree is a right child
392
 				if (tree == tree->parent->right)
392
 				if (tree == tree->parent->right)
393
 				{
393
 				{
394
-					tree_rotate_left(root, tree->parent); 
395
-					tree = tree->left; 
394
+					tree_rotate_left(root, tree->parent);
395
+					tree = tree->left;
396
 				}
396
 				}
397
 
397
 
398
-				tree->parent->color = RB_BLACK; 
399
-				tree->parent->parent->color = RB_RED; 
400
-				tree_rotate_right(root, tree->parent->parent); 
401
-         } 
402
-		} 
398
+				tree->parent->color = RB_BLACK;
399
+				tree->parent->parent->color = RB_RED;
400
+				tree_rotate_right(root, tree->parent->parent);
401
+         }
402
+		}
403
 		else // Parent is a right child
403
 		else // Parent is a right child
404
-		{  
405
-			// Tree's left uncle 
404
+		{
405
+			// Tree's left uncle
406
 			uncle = tree->parent->parent->left;
406
 			uncle = tree->parent->parent->left;
407
-			
407
+
408
 			// Parent and Uncle are RED
408
 			// Parent and Uncle are RED
409
          if ((uncle) && (uncle->color == RB_RED))
409
          if ((uncle) && (uncle->color == RB_RED))
410
-			{ 
410
+			{
411
            // Change Parent and Uncle to BLACK, make grandparent RED
411
            // Change Parent and Uncle to BLACK, make grandparent RED
412
            tree->parent->color = RB_BLACK;
412
            tree->parent->color = RB_BLACK;
413
-           uncle->color = RB_BLACK; 
413
+           uncle->color = RB_BLACK;
414
            tree->parent->parent->color = RB_RED;
414
            tree->parent->parent->color = RB_RED;
415
 
415
 
416
-			  // Continue from grandparent 
416
+			  // Continue from grandparent
417
            tree = tree->parent->parent;
417
            tree = tree->parent->parent;
418
-         } 
418
+         }
419
          else  // Parent is RED and Uncle is BLACK
419
          else  // Parent is RED and Uncle is BLACK
420
 			{
420
 			{
421
-				// Tree is a left child 
421
+				// Tree is a left child
422
 				if (tree == tree->parent->left)
422
 				if (tree == tree->parent->left)
423
 				{
423
 				{
424
-					tree_rotate_right(root, tree->parent); 
425
-					tree = tree->right; 
424
+					tree_rotate_right(root, tree->parent);
425
+					tree = tree->right;
426
 				}
426
 				}
427
 
427
 
428
-				tree->parent->color = RB_BLACK; 
429
-				tree->parent->parent->color = RB_RED; 
430
-				tree_rotate_left(root, tree->parent->parent); 
431
-         } 
432
-		} 
428
+				tree->parent->color = RB_BLACK;
429
+				tree->parent->parent->color = RB_RED;
430
+				tree_rotate_left(root, tree->parent->parent);
431
+         }
432
+		}
433
 	}
433
 	}
434
 
434
 
435
 	(*root)->color = RB_BLACK;
435
 	(*root)->color = RB_BLACK;
450
 		i += tree_print(tree->left, print_func);
450
 		i += tree_print(tree->left, print_func);
451
 		printf(",\n");
451
 		printf(",\n");
452
 	}
452
 	}
453
-	
453
+
454
 	if (tree->data && print_func)
454
 	if (tree->data && print_func)
455
 	{
455
 	{
456
 		(*print_func)(tree->data);
456
 		(*print_func)(tree->data);
457
 
457
 
458
 #ifdef DEBUG_MEMEORY_RBTREE
458
 #ifdef DEBUG_MEMEORY_RBTREE
459
-		printf(" :%s%s)", 
459
+		printf(" :%s%s)",
460
 				 (!tree->parent) ? " (root, " : " ("),
460
 				 (!tree->parent) ? " (root, " : " ("),
461
 				 (tree->color == RB_BLACK) ? "black" : "red");
461
 				 (tree->color == RB_BLACK) ? "black" : "red");
462
 #endif
462
 #endif
463
 	}
463
 	}
464
 
464
 
465
 	++i;
465
 	++i;
466
-	
466
+
467
 	if (tree->right)
467
 	if (tree->right)
468
 	{
468
 	{
469
 		printf(",\n");
469
 		printf(",\n");
472
 
472
 
473
 	if (!tree->parent)
473
 	if (!tree->parent)
474
 	{
474
 	{
475
-		printf("\n%i nodes, %u bytes each : %i bytes\n", 
475
+		printf("\n%i nodes, %u bytes each : %i bytes\n",
476
 				 i, sizeof(rbtree_t), i * sizeof(rbtree_t));
476
 				 i, sizeof(rbtree_t), i * sizeof(rbtree_t));
477
 	}
477
 	}
478
 
478
 
548
 		}
548
 		}
549
 
549
 
550
 		return predecessor;
550
 		return predecessor;
551
-	}		
551
+	}
552
 }
552
 }
553
 
553
 
554
 
554
 
566
 
566
 
567
 	while ((tree != (*root)) && (tree->color == RB_BLACK)) // was parent->color
567
 	while ((tree != (*root)) && (tree->color == RB_BLACK)) // was parent->color
568
 	{
568
 	{
569
-		if (tree == parent->left) 
569
+		if (tree == parent->left)
570
 		{
570
 		{
571
 			sibling = parent->right;
571
 			sibling = parent->right;
572
 
572
 
674
 }
674
 }
675
 
675
 
676
 
676
 
677
-void tree_remove(rbtree_t **root, rbtree_t *tree) 
677
+void tree_remove(rbtree_t **root, rbtree_t *tree)
678
 {
678
 {
679
 	rbtree_t *left, *right, *parent, *prev, *cur;
679
 	rbtree_t *left, *right, *parent, *prev, *cur;
680
 
680
 
782
 {
782
 {
783
 	if (meminfo)
783
 	if (meminfo)
784
 	{
784
 	{
785
-		printf("<addr 0x%08lx, sz %lu, \"%s\":%u>", 
786
-				 meminfo->address, 
785
+		printf("<addr 0x%08lx, sz %lu, \"%s\":%u>",
786
+				 meminfo->address,
787
 				 meminfo->size,
787
 				 meminfo->size,
788
-				 (!meminfo->filename) ? "?" : meminfo->filename->filename, 
789
-				 meminfo->line); 
788
+				 (!meminfo->filename) ? "?" : meminfo->filename->filename,
789
+				 meminfo->line);
790
 	}
790
 	}
791
 }
791
 }
792
 
792
 
852
 
852
 
853
 	while (cur)
853
 	while (cur)
854
 	{
854
 	{
855
-		printf(" %s : ( %lu bytes, %3.2f%% )\n", 
856
-				 cur->filename, cur->size, 
855
+		printf(" %s : ( %lu bytes, %3.2f%% )\n",
856
+				 cur->filename, cur->size,
857
 				 100.0 * ((float)cur->size / (float)MEMEORY_USED));
857
 				 100.0 * ((float)cur->size / (float)MEMEORY_USED));
858
 
858
 
859
 		cur = cur->next;
859
 		cur = cur->next;
883
 					break;
883
 					break;
884
 				}
884
 				}
885
 			}
885
 			}
886
-			
886
+
887
 			printf("\n");
887
 			printf("\n");
888
 		}
888
 		}
889
 
889
 
894
 
894
 
895
 	printf("Memory usage summary:\n");
895
 	printf("Memory usage summary:\n");
896
 
896
 
897
-	printf(" Tracked program memory    : %lu bytes \t(%.2f MB)\n", 
897
+	printf(" Tracked program memory    : %lu bytes \t(%.2f MB)\n",
898
 			 MEMEORY_USED, (double)MEMEORY_USED / 1024000.0);
898
 			 MEMEORY_USED, (double)MEMEORY_USED / 1024000.0);
899
-	printf(" Untracked overhead memory : %lu bytes \t(%.2f MB)\n", 
899
+	printf(" Untracked overhead memory : %lu bytes \t(%.2f MB)\n",
900
 			 MEMEORYA_USED, (double)MEMEORYA_USED / 1024000.0);
900
 			 MEMEORYA_USED, (double)MEMEORYA_USED / 1024000.0);
901
-	printf(" Untracked m-string memory : %lu bytes\n", 
901
+	printf(" Untracked m-string memory : %lu bytes\n",
902
 			 MEMEORYC_USED);
902
 			 MEMEORYC_USED);
903
 
903
 
904
-	printf("\n Total accounted memory    : %lu bytes \t(%.2f MB)\n", 
904
+	printf("\n Total accounted memory    : %lu bytes \t(%.2f MB)\n",
905
 			 MEMEORY_USED + MEMEORYA_USED + MEMEORYC_USED,
905
 			 MEMEORY_USED + MEMEORYA_USED + MEMEORYC_USED,
906
 			 (double)(MEMEORY_USED + MEMEORYA_USED + MEMEORYC_USED) / 1024000.0);
906
 			 (double)(MEMEORY_USED + MEMEORYA_USED + MEMEORYC_USED) / 1024000.0);
907
 
907
 
909
 
909
 
910
 	printf("Memory max usage summary:\n");
910
 	printf("Memory max usage summary:\n");
911
 
911
 
912
-	printf(" Tracked program memory    : %lu bytes \t(%.2f MB)\n", 
912
+	printf(" Tracked program memory    : %lu bytes \t(%.2f MB)\n",
913
 			 MAX_MEMEORY_USED, (double)MAX_MEMEORY_USED / 1024000.0);
913
 			 MAX_MEMEORY_USED, (double)MAX_MEMEORY_USED / 1024000.0);
914
-	printf(" Untracked overhead memory : %lu bytes \t(%.2f MB)\n", 
914
+	printf(" Untracked overhead memory : %lu bytes \t(%.2f MB)\n",
915
 			 MAX_MEMEORYA_USED, (double)MAX_MEMEORYA_USED / 1024000.0);
915
 			 MAX_MEMEORYA_USED, (double)MAX_MEMEORYA_USED / 1024000.0);
916
-	printf(" Untracked m-string memory : %lu bytes\n", 
916
+	printf(" Untracked m-string memory : %lu bytes\n",
917
 			 MAX_MEMEORYC_USED);
917
 			 MAX_MEMEORYC_USED);
918
 
918
 
919
-	printf("\n Total accounted memory    : %lu bytes \t(%.2f MB)\n", 
919
+	printf("\n Total accounted memory    : %lu bytes \t(%.2f MB)\n",
920
 			 MAX_MEMEORY_USED + MAX_MEMEORYA_USED + MAX_MEMEORYC_USED,
920
 			 MAX_MEMEORY_USED + MAX_MEMEORYA_USED + MAX_MEMEORYC_USED,
921
 			 (double)(MAX_MEMEORY_USED + MAX_MEMEORYA_USED + MAX_MEMEORYC_USED) / 1024000.0);
921
 			 (double)(MAX_MEMEORY_USED + MAX_MEMEORYA_USED + MAX_MEMEORYC_USED) / 1024000.0);
922
 
922
 
933
 	printf(" Memeory status report\n");
933
 	printf(" Memeory status report\n");
934
 	printf("============================================================\n");
934
 	printf("============================================================\n");
935
 	printf("Memory tracking table:\n");
935
 	printf("Memory tracking table:\n");
936
-	i = tree_print(MEMEORY_INFO, __print_meminfo);
937
-	printf("%i records, %u bytes each : %i bytes\n", 
936
+	i = tree_print(MEMEORY_INFO, (void (*)(void *))&__print_meminfo);
937
+	printf("%i records, %u bytes each : %i bytes\n",
938
 			 i, sizeof(meminfo_t), i * sizeof(meminfo_t));
938
 			 i, sizeof(meminfo_t), i * sizeof(meminfo_t));
939
 	display_memory_usage();
939
 	display_memory_usage();
940
 	printf("============================================================\n\n");
940
 	printf("============================================================\n\n");
998
 				memfile = memfile->next;
998
 				memfile = memfile->next;
999
 			}
999
 			}
1000
 		}
1000
 		}
1001
-		
1001
+
1002
 		if (!memfile)
1002
 		if (!memfile)
1003
 		{
1003
 		{
1004
 			memfile = (meminfo_filename_t *)malloc(sizeof(meminfo_filename_t));
1004
 			memfile = (meminfo_filename_t *)malloc(sizeof(meminfo_filename_t));
1090
 
1090
 
1091
 			if (meminfo->size == 0)
1091
 			if (meminfo->size == 0)
1092
 			{
1092
 			{
1093
-				printf("\nERROR: %s:%u Deallocated 0 bytes\n", 
1094
-						 (meminfo->filename) ? meminfo->filename->filename : "?", 
1093
+				printf("\nERROR: %s:%u Deallocated 0 bytes\n",
1094
+						 (meminfo->filename) ? meminfo->filename->filename : "?",
1095
 						 meminfo->line);
1095
 						 meminfo->line);
1096
 			}
1096
 			}
1097
 
1097
 
1126
 			cur = cur->next;
1126
 			cur = cur->next;
1127
 
1127
 
1128
 			MEMEORYC_USED -= sizeof(meminfo_filename_t);
1128
 			MEMEORYC_USED -= sizeof(meminfo_filename_t);
1129
-			
1129
+
1130
 			if (del->filename)
1130
 			if (del->filename)
1131
 			{
1131
 			{
1132
 				MEMEORYC_USED -= del->filename_len;
1132
 				MEMEORYC_USED -= del->filename_len;
1133
 				free(del->filename);
1133
 				free(del->filename);
1134
 			}
1134
 			}
1135
-			
1135
+
1136
 			free(del);
1136
 			free(del);
1137
 		}
1137
 		}
1138
 	}
1138
 	}
1146
 //////////////////////////////////////////////////////////////////////
1146
 //////////////////////////////////////////////////////////////////////
1147
 //////////////////////////////////////////////////////////////////////
1147
 //////////////////////////////////////////////////////////////////////
1148
 
1148
 
1149
-void *operator new(unsigned int size, const char *file, int line)
1149
+void *operator new(size_t size, const char *file, int line)
1150
 {
1150
 {
1151
 	void *ptr = (void *)malloc(size);
1151
 	void *ptr = (void *)malloc(size);
1152
-	
1153
 
1152
 
1154
 	add_track((DWORD)ptr, size, file, line);
1153
 	add_track((DWORD)ptr, size, file, line);
1155
 	return ptr;
1154
 	return ptr;
1156
 };
1155
 };
1157
 
1156
 
1158
 
1157
 
1159
-void *operator new [](unsigned int size, const char *file, int line)
1158
+void *operator new [](size_t size, const char *file, int line)
1160
 {
1159
 {
1161
 	void *ptr = (void *)malloc(size);
1160
 	void *ptr = (void *)malloc(size);
1162
-	
1163
 
1161
 
1164
 	add_track((DWORD)ptr, size, file, line);
1162
 	add_track((DWORD)ptr, size, file, line);
1165
 	return ptr;
1163
 	return ptr;

+ 18
- 14
src/memeory_test.h View File

1
 /* -*- Mode: C++; tab-width: 3; indent-tabs-mode: t; c-basic-offset: 3 -*- */
1
 /* -*- Mode: C++; tab-width: 3; indent-tabs-mode: t; c-basic-offset: 3 -*- */
2
 /*================================================================
2
 /*================================================================
3
- * 
3
+ *
4
  * Project : MTK
4
  * Project : MTK
5
  * Author  : Terry 'Mongoose' Hendrix II
5
  * Author  : Terry 'Mongoose' Hendrix II
6
  * Website : http://www.westga.edu/~stu7440/
6
  * Website : http://www.westga.edu/~stu7440/
7
  * Email   : stu7440@westga.edu
7
  * Email   : stu7440@westga.edu
8
- * Object  : 
8
+ * Object  :
9
  * License : No use w/o permission (C) 2002 Mongoose
9
  * License : No use w/o permission (C) 2002 Mongoose
10
  * Comments: Memory testing tool kit
10
  * Comments: Memory testing tool kit
11
  *
11
  *
12
  *
12
  *
13
- *           This file was generated using Mongoose's C++ 
13
+ *           This file was generated using Mongoose's C++
14
  *           template generator script.  <stu7440@westga.edu>
14
  *           template generator script.  <stu7440@westga.edu>
15
- * 
16
- *-- History ------------------------------------------------ 
15
+ *
16
+ *-- History ------------------------------------------------
17
  *
17
  *
18
  * 2002.03.27:
18
  * 2002.03.27:
19
  * Mongoose - Created
19
  * Mongoose - Created
20
  ================================================================*/
20
  ================================================================*/
21
 
21
 
22
+#include <cstddef>
22
 
23
 
23
 #ifndef __MTK_MONGOOSE_MEMEORY_TEST_H_
24
 #ifndef __MTK_MONGOOSE_MEMEORY_TEST_H_
24
 #define __MTK_MONGOOSE_MEMEORY_TEST_H_
25
 #define __MTK_MONGOOSE_MEMEORY_TEST_H_
25
 
26
 
26
 #ifdef DEBUG_MEMEORY
27
 #ifdef DEBUG_MEMEORY
27
-#   define DEBUG_NEW new(__FILE__, __LINE__)
28
-void *operator new(unsigned int size, const char *file, int line);
29
-void *operator new [](unsigned int size, const char *file, int line);
30
 
28
 
29
+#define DEBUG_NEW new(__FILE__, __LINE__)
30
+void *operator new(size_t size, const char *file, int line);
31
+void *operator new [](size_t size, const char *file, int line);
31
 
32
 
32
 #define DEBUG_DELETE delete_check(__FILE__, __LINE__, 0);delete
33
 #define DEBUG_DELETE delete_check(__FILE__, __LINE__, 0);delete
33
 void operator delete(void *p);
34
 void operator delete(void *p);
34
 void operator delete [](void *p);
35
 void operator delete [](void *p);
36
+
35
 #else
37
 #else
36
-#   define DEBUG_NEW new
37
-#   define DEBUG_DELETE delete
38
+
39
+#define DEBUG_NEW new
40
+#define DEBUG_DELETE delete
41
+
38
 #endif
42
 #endif
39
 
43
 
40
 #define new DEBUG_NEW
44
 #define new DEBUG_NEW
47
 
51
 
48
 	long memory_used();
52
 	long memory_used();
49
 	/*------------------------------------------------------
53
 	/*------------------------------------------------------
50
-	 * Pre  : 
54
+	 * Pre  :
51
 	 * Post : Returns amount of total memory used
55
 	 * Post : Returns amount of total memory used
52
 	 *
56
 	 *
53
 	 *-- History ------------------------------------------
57
 	 *-- History ------------------------------------------
54
 	 *
58
 	 *
55
-	 * 2002.03.27: 
59
+	 * 2002.03.27:
56
 	 * Mongoose - Created
60
 	 * Mongoose - Created
57
 	 ------------------------------------------------------*/
61
 	 ------------------------------------------------------*/
58
 
62
 
59
 	void dump_memory_report();
63
 	void dump_memory_report();
60
 	/*------------------------------------------------------
64
 	/*------------------------------------------------------
61
-	 * Pre  : 
65
+	 * Pre  :
62
 	 * Post : Dumps raw Tree holding memeory accounting
66
 	 * Post : Dumps raw Tree holding memeory accounting
63
 	 *
67
 	 *
64
 	 *-- History ------------------------------------------
68
 	 *-- History ------------------------------------------
65
 	 *
69
 	 *
66
-	 * 2002.03.27: 
70
+	 * 2002.03.27:
67
 	 * Mongoose - Created
71
 	 * Mongoose - Created
68
 	 ------------------------------------------------------*/
72
 	 ------------------------------------------------------*/
69
 
73
 

Loading…
Cancel
Save