让你的32位WIN7突破3GB的可用内存限制

Though machines with 4GB are not yet the typical purchase for home or business use, they are readily available from major manufacturers and it won’t be long before they are the typical purchase. But there are problems. You don’t have to stand for long in a computer shop to hear a sales assistant talk of 4GB as some sort of limit for 32-bit operating systems, and it won’t be long before this sales patter develops into outright promotion of 64-bit Windows as the only way to get past this limit. Some sense of this can be seen already in manufacturers’ advertising materials, as in the following fine print from Dell:


The total amount of available memory will be less than 4GB. The amount less depends on the actual system configuration. To fully utilise 4GB or more of memory requires a 64-bit enabled processor and 64-bit operating system, available on selected systems only.

Let me stress now that I do not complain about Dell’s statement. Its first two sentences are correct for all 32-bit editions of Windows Vista exactly as configured by Microsoft and installed by Dell. In the last sentence, I might quibble that the talk of a 64-bit processor is superfluous since the machine on offer does have such a processor, but otherwise the sentence is correct because of the word fully. Yet although Dell’s statement is true, it is not the whole truth: there is something that Microsoft does not tell you, and perhaps does not tell Dell.

That 32-bit editions of Windows Vista are limited to 4GB is not because of any technical constraint on 32-bit operating systems. The 32-bit editions of Windows Vista all contain code for using physical memory above 4GB. Microsoft just doesn’t license you to use that code.

Well, to say it that way is perhaps to put words in Microsoft’s mouth. I say the restriction to 4GB is a licensing issue because that’s how Microsoft’s programmers evidently have thought of it. The 4GB limit is retrieved from the registry by calling a function named ZwQueryLicenseValue, which is itself called from an internal procedure which Microsoft’s published symbol files name as MxMemoryLicense. If you remove this check for the licensed memory limit then a restriction to 4GB is demonstrably not enforced by other means. Yet I must admit that I have not found where Microsoft says directly that 32-bit Windows Vista is limited to 4GB only by licensing. The supposed License Agreement doesn’t even mention the word memory. What, really, is going on?

阅读剩余部分...

谁动了我们的CPI?

不解释系列。

LUA学习(1)lua介绍和与C++混编

    今天闲来没事,学习了下lua,发现lua是一门很好上手的语言,核心很紧凑,而扩展库很多,可以支持socket,多线程,图形编程等。可惜国内的lua社区并不火,但好在有不少前辈已经为我们摸索出了一条康庄大道,并且博客资源很丰富,质量也不错。

Lua是一个嵌入式的脚本语言,它不仅可以单独使用还能与其它语言混合调用。
Lua与其它脚本语言相比,其突出优势在于:

  1. 可扩展性。Lua的扩展性非常卓越,以至于很多人把Lua用作搭建领域语言的工具(注:比如游戏脚本)。Lua被设计为易于扩展的,可以通过Lua代码或者 C代码扩展,Lua的很多功能都是通过外部库来扩展的。Lua很容易与C/C++、java、fortran、Smalltalk、Ada,以及其他语言接口。
  2. 简单。Lua本身简单,小巧;内容少但功能强大,这使得Lua易于学习,很容易实现一些小的应用。并且lua现在的库已经很齐备了,虽然说和python还有差距,但是毕竟二者所专注的领域不同。
  3. 高效率。Lua有很高的执行效率,统计表明Lua是目前平均效率很高的脚本语言,执行效率可以达到C语言的1/10。
  4. 与平台无关。Lua不是通过使用条件编译实现平台无关,而是完全使用ANSI (ISO) C,这意味着只要你有ANSI C编译器你就可以编译并使用Lua。
可以到 http://code.google.com/p/luaforwindows/ 下载lua5.1 for windows版的二进制文件,最新版本是2011年6月放出来的lua 5.1.45,这也是我使用的版本。其已经内置了很多常用的库,以及一个继承的开发环境scite,以及一堆example和手册,以及一个QuickLuaTour。安装过程不详述了。
安装后,打开scite,输入代码后按F5,即可完成编辑和执行的过程。
注意:lua虽然属于脚本,但是仍有一个编译的过程,会编译成luac为后缀的字节码文件,也可直接解释执行。

第一个例子
print("hello world")
print "hello world"

运行后即可看到结果。需要注意的是lua代码没有分号作为结尾的,也没有控制结构中常见的花括号{}。
完整的demo如下:
print("Hello World.".."haha")
-- 两个下划线是注释
-- print 5*2 这样是错误的,只有字符串和table才能不加引号
print(5*2)
-- 自定义函数,没有{},也没有分号
function gougudli(a,b)
    local c2=a^2+b^2
    return math.sqrt(c2)
end
print(gougudli(6,8))
--循环和判断结构
for i=1,15,2 do
-- lua中用两个点连接变量
print("now i is\t"..i)
if i<2 then
print("small")
elseif i<7 then
print "medium"
else
print("big")
end
end
index=1
repeat
index=index+1
print(index)
until index==6
--table是LUA里重要并且唯一的复合数据结构
mydata={}
mydata[0]=1985
mydata["name"]="waitfox"
for key,value in pairs(mydata) do
print(key.."="..value)
end
-- 可变参数的函数
function free_print(...)
for i=1,arg.n do print(arg[i]) end
end
free_print("one","two")
--以table作参数
function print_table(t)
for k,v in pairs(t) do print(v) end
end
print_table{1,2,5,"good",10}

前面还说过,lua是很容易扩展的,并且与C有很亲的血缘关系,那么lua与C混编也应该是很容易实现的了。
示例如下:
(1)使用MSVC新建一个空的工程,这里我用的是VC6。在工具-选项-目录中设置好头文件和lib库的地址;
(2)工程-属性,在对象/库模块中添加 lua51.lib;
(3)代码如下:
#include "stdafx.h"
extern "C"
{
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
}
int main(int argc, char *argv[]) {   
lua_State *L = lua_open();//装载lua堆栈
luaL_openlibs(L);
   if (NULL == L)
   {
      printf("Error Initializing lua\n");
      return -1;
   }
char line[BUFSIZ];
while (fgets(line, sizeof(line), stdin) != 0){    
luaL_dostring(L,line);
 }
 lua_close(L);
return 0;
}

编译-组建后,即可看到你需要的结果,将出现一个窗口,输入单行LUA命令,即可执行lua脚本。
如图所示:
2011-09-14_163219.jpg
注意:(1)lua5.1不论是和lua4或者是lua5.0相比,其一些宏定义和函数用法都有了一些变化。如果你是在网上看到的教程,无法运行,或运行结果与期望不符,很可能是版本问题。
(2)如果在编译过程中出现以下错误,请严格按照示例代码引入头文件,并使用正确的函数名。
比如:
cannot convert from 'int' to 'struct lua_State *' 这是由于没有引入lauxlib.h造成的。
'lua_dostring' : undeclared identifier 这是由于lua5.1中此函数名不存在造成的,实际上此函数已经更名为luaL_dostring。
可能网上很多示例都是基于较早的版本,尤其需要注意,你遇到的种种疑难杂症,很可能就是版本问题。
BTW:scite存在选择半个中文字乱码,或者是编辑中文时就会乱码。这需要修改global 配置文件。
修改下面的选项为:
code.page=936
output.code.page=936

C语言中的序列点

此文针对phpchina中的一篇文章而写,可到此围观。
http://bbs.phpchina.com/thread-221621-1-3.html
#include<stdio.h>
main(){
       int i=5,j=5,q,p;
       p = (++i)+(++i)+(++i);
       q = (j++)+(j++)+(j++);
       printf("%d,%d",p,q);
       system("pause");
}
打印出 :22,15
<?php
$i=5;
$m=5;
$b = (++$m)+(++$m)+(++$m);
$d = ($i++)+($i++)+($i++);
echo $b,'--',$d;
输出:21--18
为啥不一样呢?
C的输出感觉不对似的。。。用linux的GCC 和win下面的DEV C++都是 22,15 。。。跟什么有关系吗?

      这个问题其实就是C里面常常被提到的序列点问题,此代码的执行顺序由编译器自行决定。先介绍两个概念。
     副作用:对数据对象或者文件的修改。
    序列点:是一个时间点(在整个表达式全部计算完毕之后或在 ||、 &&、 ? : 或逗号运算符处, 或在函数调用之前), 此刻尘埃落定, 所有的副作用都已确保结束。

阅读剩余部分...

    Page :
  1. 1