inffas32.asm: error A2070: invalid instruction operands

I got the following errors while compiling zlib on windows with Visual studio 2005:

1>inffas32.asm(649) : error A2070: invalid instruction operands
1>inffas32.asm(663) : error A2070: invalid instruction operands
1>inffas32.asm(720) : error A2070: invalid instruction operands

these errors are due to an issue with Microsoft Macro Assembler ,included with Visual C++ 2005.it refuses to assemble a MOVD instruction with a memory operand with an implied size, and requires that "dword ptr" prefix the memory operand.

to fix these problems,simply addingDWORD PTR’ before the operands:

movd mm5,dword ptr [esp+4](649)
movd mm7,dword ptr [esi](663)
movd mm7,dword ptr [esi](720)

Continue reading “inffas32.asm: error A2070: invalid instruction operands”

Windows Live Space says:"Server is too busy"

What the hell is going on?Too many users or bad design?I would rather believe it’s the first case. because there are ton of amazing articles written by Microsoft about Scalability and Availability,such as “Scalability, Sweet Scalability” or “Improving Both Availability and Scalability“. they can’t possibly have made an incredibly dumb mistake.

I don’t know what happened and I don’t want to know.I only know that I even can’t leave a comment to my friends who have written on Windows Live Space till now.

msn_space_busy

Compiler warning C4022 when building OpenSSL 0.9.8e On Windows

I got the following compiler error when building OpenSSL-0.9.8e in Windows environments with Visual studio 2005:

.\apps\enc.c(380) : error C2220: warning treated as error – no ‘object’ file generated
.\apps\enc.c(380) : warning C4022: ‘BIO_ctrl’ : pointer mismatch for actual parameter 4

Here is the quick fix to solve this compile error:

Open file .\apps\enc.c,Go to line 380:

if (BIO_read_filename(in,inf <= 0))
{
perror(inf);
goto end;
}

 Change it to

if (BIO_read_filename(in,(char*)(inf <= 0)))
{
perror(inf);
goto end;
}

you can download the compiled binary here.

How to detect whether or not user is running a full-screen program

Recently I was asked how to detect whether or not user is runing a full screen program,here is the code snippet: 

bool IsFullScreenMode()
{
  int w = GetSystemMetrics(SM_CXSCREEN);
  int h = GetSystemMetrics(SM_CYSCREEN); 

  HWND hWnd = 0;
  while (hWnd = FindWindowEx(NULL, hWnd, NULL, NULL))
  {
    if (GetWindowLong(hWnd, GWL_EXSTYLE) & WS_EX_TOPMOST)
    {
      RECT rcWindow;
      GetWindowRect(hWnd, &rcWindow);
      if ((w == (rcWindow.right - rcWindow.left)) &&
         (h == (rcWindow.bottom - rcWindow.top)))
           return true; 
     }
  } 
  return false;
}

windows下内存分配方式的性能对比

今天写了一个小程序测试了一下在windows系统上不同内存分配方式间的性能差异,比较内容:VirtualAlloc,malloc,new,和HeapAlloc。代码很简单,循环分配并释放内存,最后计算每种方法所耗用的时间。

测试结果:

Virtual Memory total time:125,kernel:125,user:0
new total time:203,kernel:171,user:31
malloc total time:125,kernel:125,user:0
heap total time:125,kernel:109,user:15
Press any key to continue . . .

代码:

#include "stdafx.h"
#include "dlclib.h"
#include
using namespace std;
const int LOOPS = 1000;

void PrintResult(CProfileWatch& watch, LPCSTR pszMethod)
{
cout << pszMethod << "t"
<< "total time:" << watch.GetTotalTimeElapsedMs()
<< ",kernel:" << watch.GetKernelTimeElapsedMs()
<< ",user:" << watch.GetUserTimeElapsedMs()
<< "n";
}
int _tmain(int argc, _TCHAR* argv[])
{
SYSTEM_INFO info;
::GetSystemInfo(&info);
DWORD dwPageSize = info.dwPageSize;
CProfileWatch watch;
DWORD dwSize = MemAlign(1024 * 1024 * 10, dwPageSize);
watch.Start();
for (int i = 0; i < LOOPS; ++i)
{
void* pMem = ::VirtualAlloc(NULL, dwSize, MEM_RESERVE |
MEM_COMMIT | MEM_TOP_DOWN, PAGE_READWRITE);
::VirtualFree(pMem, 0, MEM_RELEASE);
}
watch.Stop();
PrintResult(watch, "Virtual Memory");

watch.Start();
for (int i = 0; i < LOOPS; ++i)
{
void* pMem = new char[dwSize];
delete []pMem;
}
watch.Stop();
PrintResult(watch, "new");

watch.Start();
for (int i = 0; i < LOOPS; ++i)
{
void* pMem = malloc(dwSize);
free(pMem);
}
watch.Stop();
PrintResult(watch, "malloc");
HANDLE hHeap = ::HeapCreate(HEAP_NO_SERIALIZE, 0, 0);
watch.Start();
for (int i = 0; i < LOOPS; ++i)
{
void* pMem = ::HeapAlloc(hHeap, HEAP_NO_SERIALIZE, dwSize);
::HeapFree(hHeap, HEAP_NO_SERIALIZE, pMem);
}
watch.Stop();
PrintResult(watch, "heap");
::HeapDestroy(hHeap);
return 0;

}