00001
00002
00003
00004
00005 #ifdef _MSC_VER
00006 #include <Windows.h>
00007 #else
00008 #include <sys/resource.h>
00009 #endif
00010 #include "../includes/getmaxMALLOC.h"
00011
00012 #ifdef _MSC_VER
00013 IMPORT_EXPORT_MALLOC_DLL unsigned long GetLargestFreeMemoryRegion(void)
00014 {
00015 SYSTEM_INFO systemInfo;
00016 VOID *p = 0;
00017 MEMORY_BASIC_INFORMATION mbi;
00018 unsigned long largestSize = 0;
00019
00020 GetSystemInfo(&systemInfo);
00021
00022 while(p < systemInfo.lpMaximumApplicationAddress)
00023 {
00024 SIZE_T dwRet = VirtualQuery(p, &mbi, sizeof(mbi));
00025 if (dwRet > 0)
00026 {
00027 if (mbi.State == MEM_FREE)
00028 {
00029 if (largestSize < mbi.RegionSize)
00030 {
00031 largestSize = (unsigned long) mbi.RegionSize;
00032 }
00033 }
00034 p = (void*) (((char*)p) + mbi.RegionSize);
00035 }
00036 else
00037 {
00038 p = (void*) (((char*)p) + systemInfo.dwPageSize);
00039 }
00040 }
00041 return largestSize;
00042 }
00043
00044 #else
00045 IMPORT_EXPORT_MALLOC_DLL unsigned long GetLargestFreeMemoryRegion(void)
00046 {
00047 struct rlimit rlim;
00048 unsigned long largestSize = 0;
00049
00050
00051 #ifdef solaris
00052 getrlimit(RLIMIT_VMEM,&rlim);
00053 #else
00054 getrlimit(RLIMIT_MEMLOCK, &rlim);
00055 #endif
00056 largestSize = rlim.rlim_max;
00057
00058 return largestSize;
00059 }
00060 #endif
00061