Suphelp64
- Suphelp64 是 agine 在 171024.1 中新加入的特性。agine kernel 是基于 x86 平台编译生成的,因此,当运行在基于 x64 体系架构的 CPU 及其 OS 时并不能充分利用 x64 平台架构的性能优势。为此,我们在当前版本中加入了 Suphelp64 这一全新特性。
- Suphelp64 提供了虚拟化环境,其允许在部分场景下执行 x64 代码。
比如我们在编写用户扩展程序时经常(或许)用到的:
// The declaration contains the necessary header files
#include <h.studio>
// Frequently used functions...
malloc(...);
copy(...);
free(...);
...
或者,我们在开发基于 Web 的用户扩展程序时经常用到的:
// This includes the h.message header file to support Web API
#include <h.message>
// Frequently used functions...
message(...);
echo(...);
GetPost(...);
GetPara(...);
...
等...但这些 function / API 均是基于 x86 平台而开发的,并不能在基于 x64 平台架构的 CPU 及其 OS 中充分利用其性能优势。
但从 agine 171024.1 版本开始,您可以通过在实例配置文件(.conf)中加入如下代码以启用 Suphelp64:
// Suphelp64 Conf
object suphelp64{
optload true; // 正常加载 suphelp64 环境(仅支持 x64 体系)
}
当启用 Suphelp64 后,Suphelp64 内核扩展会自动基于 agine 底层将部分 User API 重定位。并通过中间件兼容转换以执行其 x64 平台版本,从而提升用户扩展执行性能。
例如,您在用户扩展程序中调用 NewMemory function 试图在当前用户扩展进程中分配一块指定大小的内存区域时,其实际却被自动重定位调用了 Suphelp64NewMemory function. 下面代码演示了上述操作。
// The declaration contains the necessary header files
#include <h.studio>
// Allocate memory
int p=malloc(12); // malloc -> NewMemory -> Suphelp64NewMemory...
if(p){
mwrite(p,toBytes("hello world!"),12); // mwrite -> WriteMemory -> Suphelp64WriteMemory...
free(p); // free -> DelMemory -> Suphelp64DelMemory...
}
而 Suphelp64NewMemory function 并不是基于 x64 平台实现的,其作用仅是将 x86 模式转换为 x64 模式并转换其数据。也就是说,该 function 起到了中间件兼容的作用。而基于 x64 平台实现的 API 为 Kernel API KiSuphelp64NewMemory function.
简而言之,Suphelp64 特性通过在 agine 底层构建虚拟环境以实现部分 User API 通过基于 x64 平台代码实现,从而提升了其用户扩展程序的执行性能。在当前版本中,您可以在不更改、不重新生成扩展程序的情况下启用或禁用 Suphelp64 环境。