wdenk | c7de829 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 1 | /**************************************************************************** |
| 2 | * |
| 3 | * SciTech OS Portability Manager Library |
| 4 | * |
| 5 | * ======================================================================== |
| 6 | * |
| 7 | * The contents of this file are subject to the SciTech MGL Public |
| 8 | * License Version 1.0 (the "License"); you may not use this file |
| 9 | * except in compliance with the License. You may obtain a copy of |
| 10 | * the License at http://www.scitechsoft.com/mgl-license.txt |
| 11 | * |
| 12 | * Software distributed under the License is distributed on an |
| 13 | * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or |
| 14 | * implied. See the License for the specific language governing |
| 15 | * rights and limitations under the License. |
| 16 | * |
| 17 | * The Original Code is Copyright (C) 1991-1998 SciTech Software, Inc. |
| 18 | * |
| 19 | * The Initial Developer of the Original Code is SciTech Software, Inc. |
| 20 | * All Rights Reserved. |
| 21 | * |
| 22 | * ======================================================================== |
| 23 | * |
| 24 | * |
| 25 | * Language: ANSI C |
| 26 | * Environment: any |
| 27 | * |
| 28 | * Description: Test program to determine just how much memory can be |
| 29 | * allocated with the compiler in use. Compile and link |
| 30 | * with the appropriate command line for your DOS extender. |
| 31 | * |
| 32 | * Functions tested: PM_malloc() |
| 33 | * PM_availableMemory() |
| 34 | * |
| 35 | * |
| 36 | ****************************************************************************/ |
| 37 | |
| 38 | #include <stdlib.h> |
| 39 | #include <stdio.h> |
| 40 | #include <string.h> |
| 41 | #include <math.h> |
| 42 | #include "pmapi.h" |
| 43 | |
| 44 | #ifdef __16BIT__ |
| 45 | #define MAXALLOC 64 |
| 46 | #else |
| 47 | #define MAXALLOC 2000 |
| 48 | #endif |
| 49 | |
| 50 | int main(void) |
| 51 | { |
| 52 | int i; |
| 53 | ulong allocs; |
| 54 | ulong physical,total; |
| 55 | char *p,*pa[MAXALLOC]; |
| 56 | |
| 57 | printf("Program running in "); |
| 58 | switch (PM_getModeType()) { |
| 59 | case PM_realMode: |
| 60 | printf("real mode.\n\n"); |
| 61 | break; |
| 62 | case PM_286: |
| 63 | printf("16 bit protected mode.\n\n"); |
| 64 | break; |
| 65 | case PM_386: |
| 66 | printf("32 bit protected mode.\n\n"); |
| 67 | break; |
| 68 | } |
| 69 | |
| 70 | printf("Memory available at start:\n"); |
| 71 | PM_availableMemory(&physical,&total); |
| 72 | printf(" Physical memory: %ld Kb\n", physical / 1024); |
| 73 | printf(" Total (including virtual): %ld Kb\n", total / 1024); |
| 74 | printf("\n"); |
| 75 | for (allocs = i = 0; i < MAXALLOC; i++) { |
| 76 | if ((pa[i] = PM_malloc(10*1024)) != 0) { /* in 10k blocks */ |
| 77 | p = pa[allocs]; |
| 78 | memset(p, 0, 10*1024); /* touch every byte */ |
| 79 | *p = 'x'; /* do something, anything with */ |
| 80 | p[1023] = 'y'; /* the allocated memory */ |
| 81 | allocs++; |
| 82 | printf("Allocated %lu bytes\r", 10*(allocs << 10)); |
| 83 | } |
| 84 | else break; |
| 85 | if (PM_kbhit() && (PM_getch() == 0x1B)) |
| 86 | break; |
| 87 | } |
| 88 | |
| 89 | printf("\n\nAllocated total of %lu bytes\n", 10 * (allocs << 10)); |
| 90 | |
| 91 | printf("\nMemory available at end:\n"); |
| 92 | PM_availableMemory(&physical,&total); |
| 93 | printf(" Physical memory: %ld Kb\n", physical / 1024); |
| 94 | printf(" Total (including virtual): %ld Kb\n", total / 1024); |
| 95 | |
| 96 | for (i = allocs-1; i >= 0; i--) |
| 97 | PM_free(pa[i]); |
| 98 | |
| 99 | printf("\nMemory available after freeing all blocks (note that under protected mode\n"); |
| 100 | printf("this will most likely not be correct after freeing blocks):\n\n"); |
| 101 | PM_availableMemory(&physical,&total); |
| 102 | printf(" Physical memory: %ld Kb\n", physical / 1024); |
| 103 | printf(" Total (including virtual): %ld Kb\n", total / 1024); |
| 104 | |
| 105 | return 0; |
| 106 | } |