매번 아무 생각 없이 써온 함수인데, 최근에서야 문제점을 알았다.

MSDN 을 보니 어느샌가 아래와 같은 것이 추가 되어 있었다

GlobalMemoryStatus Function

[GlobalMemoryStatus can return incorrect information. Use the GlobalMemoryStatusEx function instead. ]

Retrieves information about the system's current usage of both physical and virtual memory.

잘못된 정보를 리턴할 수 있으니 Ex 함수를 사용하라는 것이었다.

그래서 다시 아래로 내려가 보았더니,

Remarks

On computers with more than 4 GB of memory, the GlobalMemoryStatus function can return incorrect information, reporting a value of –1 to indicate an overflow. For this reason, applications should use the GlobalMemoryStatusEx function instead.

On Intel x86 computers with more than 2 GB and less than 4 GB of memory, the GlobalMemoryStatus function will always return 2 GB in the dwTotalPhys member of the MEMORYSTATUS structure. Similarly, if the total available memory is between 2 and 4 GB, the dwAvailPhys member of the MEMORYSTATUS structure will be rounded down to 2 GB. If the executable is linked using the /LARGEADDRESSAWARE linker option, then the GlobalMemoryStatus function will return the correct amount of physical memory in both members.

The information returned by the GlobalMemoryStatus function is volatile. There is no guarantee that two sequential calls to this function will return the same information.

라고 되어 있었다.

4GB 이상일때도 문제가 있고, 2GB 에서 4GB 사이인 경우에는 항상 2GB 로 리턴한다는 문제였다. /LARGEADDRESSAWARE 로 실행되면 잘 동작한다지만 항상 그렇게 실행하도록 프로그램을 작성하는 것은 옳지못한 방법이다.

그래서 결과적으로 메모리 정보를 얻어오는 부분을 수정하기로 했다. Ex 로...

+ Recent posts