/*++ Copyright (c) 1992 Microsoft Corporation Module Name: tmpheap.c Abstract: Test program for the MP heap package. Author: John Vert (jvert) 10-Jul-1995 Revision History: --*/ #include "nt.h" #include "ntrtl.h" #include "nturtl.h" #include "windows.h" #include "stdio.h" #include "string.h" #include "stdlib.h" #include "mpheap.h" DWORD ThreadStartup( LPVOID Parameter ); LPVOID Malloc(DWORD dwBytes); VOID Free(LPVOID lpMem); BOOL Suicide = FALSE; HANDLE MpHeap; LPVOID Malloc( DWORD dwBytes ) { return(MpHeapAlloc(MpHeap,0,dwBytes)); } VOID Free( LPVOID lpMem ) { MpHeapFree(MpHeap,lpMem); } int _CRTAPI1 main (argc, argv) int argc; char *argv[]; { ULONG NumThreads; ULONG i; HANDLE *h; DWORD ThreadId; DWORD Parallelism; DWORD Seconds; ULONG StartContextSwitches; NTSTATUS Status; SYSTEM_CONTEXT_SWITCH_INFORMATION SwitchInfo; LPMPHEAP_STATISTICS HeapStats; PVOID Foo; DWORD StatSize; DWORD Error; if (argc != 4) { fprintf(stderr, "Usage: tmpheap NumThreads HeapParallelism Seconds\n"); exit(1); } NumThreads = atoi(argv[1]); Parallelism = atoi(argv[2]); Seconds = atoi(argv[3]); MpHeap = MpHeapCreate(0, 0, Parallelism); if (MpHeap == NULL) { fprintf(stderr, "MpHeapCreate failed error %d\n",GetLastError); exit(1); } h = Malloc(NumThreads * sizeof(HANDLE)); if (h==NULL) { fprintf(stderr, "Malloc thread handle array failed\n"); exit(1); } Status = NtQuerySystemInformation(SystemContextSwitchInformation, &SwitchInfo, sizeof(SwitchInfo), NULL); if (!NT_SUCCESS(Status)) { fprintf(stderr, "NtQuerySystemInformation failed %08lx\n", Status); exit(1); } StartContextSwitches = SwitchInfo.ContextSwitches; for (i=0; i 0x80); if (AllocAgain) { BufferSize = (RtlRandom(&Seed) & 0xfff) + sizeof(PUCHAR) + sizeof(ULONG); CurrentAllocs++; if (CurrentAllocs > MaxAllocs) { MaxAllocs = CurrentAllocs; } Buffer = Malloc(BufferSize); if (Buffer == NULL) { fprintf(stderr,"malloc of %d returned NULL\n",BufferSize); return(0); } CurrentSize += BufferSize; if (CurrentSize > MaxSize) { if ((CurrentSize >> 18) != (MaxSize >> 18)) { printf("Thread %x up to %d bytes %d allocs\n", GetCurrentThreadId(), CurrentSize, CurrentAllocs); } MaxSize = CurrentSize; } if ((CurrentSize > MaxSize) && (CurrentSize-MaxSize > 0x10000)) { } for (j=0; j