Category : Files from Magazines
Archive   : VOL10N11.ZIP
Filename : WINMEM.C

 
Output of file : WINMEM.C contained in archive : VOL10N11.ZIP
/*
WINMEM.C -- How much memory can we allocate under Windows?

cl -c -AS -Gsw -Oais -Zpe winmem.c
link /align:16 winmem,,,/nod:slibcew libw,win.def
rc winmem.exe

; WIN.DEF -- generic Windows .DEF file
EXETYPE WINDOWS
STUB 'WINSTUB.EXE'
CODE PRELOAD MOVEABLE DISCARDABLE
DATA PRELOAD MOVEABLE MULTIPLE
HEAPSIZE 10240
STACKSIZE 5120

or (Borland C++ 2.0; no .DEF file required):
bcc -W winmem.c
rc winmem.exe

Copyright (c) 1991 Ziff Communications Co.
PC Magazine * Andrew Schulman
*/

#include
#include
#include
#include
#include
#include
#include "windows.h"

/* printf to a Windows MessageBox */
int msgprintf(char *fmt, ...)
{
static char s[1024];
int len;
va_list marker;
va_start(marker, fmt);
len = wvsprintf((char far *) s, (char far *) fmt, marker);
va_end(marker);
MessageBox(NULL, s, "PC Magazine Windows Memory Allocation Test", MB_OK);
return len;
}

/* return name of current Windows mode - far ptr for use with wvsprintf */
char far *win_mode(void)
{
unsigned long flags = GetWinFlags();
return (flags & WF_ENHANCED ? "Enhanced" :
flags & WF_STANDARD ? "Standard" :
/* default */ "Real") ;
}

int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance,
LPSTR lpszCmdLine, int nCmdShow)
{
unsigned long blksize = 32L << 10L; /* 32k per block */
unsigned long freespace, largest, allocated, save;
time_t t1, t2;
char far *fp;

/* retrieve these BEFORE we start allocating memory */
freespace = GetFreeSpace(0);
largest = GlobalCompact(-1);

/* allocate as much memory as possible */
time(&t1);
allocated = 0;
while (fp = GlobalLock(GlobalAlloc(GMEM_MOVEABLE, blksize)))
{
*fp = 'x';
fp[blksize-1] = 'y';
allocated += blksize;
save = fp;
Yield(); /* Let another program run */
}
time(&t2);

/* display results */
msgprintf("Running in %s mode\n"
"%lu bytes available\n"
"%lu bytes in largest block\n"
"Allocated %lu bytes in %lu seconds\n"
"Sample pointer: %04X:%04X",
win_mode(),
freespace, largest, allocated, t2 - t1,
FP_SEG(save), FP_OFF(save));

/* allocated memory will be freed automatically on exit */
return 0;
}



  3 Responses to “Category : Files from Magazines
Archive   : VOL10N11.ZIP
Filename : WINMEM.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/