hotfox使用Hoard

1.关于Hoard

Hoard是一款快速,高效利用内存的的内存分配器,可以提高应用的运行速度.而且不需要修改应用代码.
Hoard is a fast, scalable, and memory-efficient memory allocator that can speed up your applications. It’s much faster than built-in system allocators:as much as 2.5x faster than Linux, 3x faster than Windows, and 7x faster than Mac. No source code changes necessary. Cross-platform: works on Linux,Solaris, Mac OS X, and Windows.

.官方站点
http://www.hoard.org/
.如何编译与使用的文档
http://people.cs.umass.edu/~emery/hoard/building.html

使用的目的:
.提高内存分配速度:减少UMX消息包的处理时间(如生成时间)
.提高内存使用效率: 降低应用对内存峰值的要求(减少系统内存碎片)

2.编译Hoard(的经历)


Hoard代码的目录为$(HOARDSRC)
cd $(HOARDSRC)
192.168.1.160上同时有vc6和vs2005的环境,系统环境变量默认情况下是使用vc6.
cl版本为:
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.

现在需要在vs2005下编译Hoard.cl版本为:
$(VSINSTALLDIR)>cl
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.42 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

以下确保使用vs2005编译.
set path=C:\Program Files\Microsoft Visual Studio 8\VC\bin;%path%
set lib=C:\Program Files\Microsoft Visual Studio 8\vc\lib;%lib%
set include=C:\Program Files\Microsoft Visual Studio 8\vc\include;%include%
set path=C:\Program Files\Microsoft Visual Studio 8\Common7\IDE;%path%

否则,会出现编译链接错误.(具体错误略)
如果不设置path,则cl会提示"没有mspdb80.dll".该文件位于$(VSINSTALLDIR)\Common7\IDE目录中.

编译hoard
compile-winhoard.cmd

编译成功后在$(HOARDSRC)目录下生成以下所需的文件:

.winhoard.dll

.winhoard.lib

.usewinhoard.obj

3.编译hotfox


先要编译ACE 5.4,Xerces-C 2.8的Release版本.(zlib,openssl已经编译)

.hotfox Release版本配置
配置名称:32_END_POINT_Release
输出文件:.\bin\hotfox.exe

.使用Hoard的hotfox版本
配置名称:use_hoard_release
输出文件:.\bin/use_hoard_hotfox.exe
附加依赖项:usewinhoard.obj winhoard.lib

4.测试及结论

4.1测试

使用xbox插件对Hoard的使用情况进行对比测试.
简单的测试逻辑:
测试得到生成相同的UMX消息包,对比时间及所需要的内存的数据。(测试数据为24列,500000条记录)

xbox测试代码如下:
int CXboxPlugin::Test3() {
    int k = 0;
    do {
        clock_t begin = clock();
        CMsg *msg = new CMsg;
    CRowset *prs = new CRowset;
        msg->AddRowset(prs);
        int fld_num = 24;
        int rec_num = 500000;
        for (int i=0;i<fld_num;i++) {
            char col_name[32];
            sprintf(col_name,"col%d",i+1);
            prs->AddField(col_name);
        }

        for (int i=0;i<rec_num;i++) {

            char value[] = "ddddddd";
            prs->AddRecord();
            for (int col=0;col<fld_num;col++) {
            prs->SetFieldValue(col,value);
            }
        }

        double duration = (double)(clock()-begin)/CLOCKS_PER_SEC;
        nlogger_->log(LO_STDOUT|LO_FILE,SEVERITY_INFO,"%d:耗时:%.2f秒.\n",k,duration);
        k++;
        if (k>1000)
            break;
        msg->Release();
    }while (1);

    return 0;
}

$(BIN)="..\..\..\..\可执行文件\服务端"

首先需要编译lssdk的Release版本.(lssdk又依赖Xalan-C).

lssdk Release的工程属性:

.输出文件:.$(BIN)\release\lssdk.dll

.导入库:..\..\lib\release\lssdk.lib

.忽略特性库:msvcrtd.lib

然后,编译xbxo.dll.

测试结果:

  耗时(秒)内存(M)
不使用Hoard( hotfox.exe)7.0在160~710之间变动
使用Hoard( use_hoard_hotfox.exe)3.3稳定在500

在调试xbox时出现以下错误

HEAP[hotfox.exe]: Invalid Address specified to RtlFreeHeap( 00DF0000, 02B42AB0 )
Windows 已在 hotfox.exe 中触发一个断点。

其原因可能是堆被损坏,这也说明 hotfox.exe 中或它所加载的任何 DLL 中有 bug。

输出窗口可能提供了更多诊断信息

发现是xbox的编译选项是/MT,修改为/MD后问题解决.解释如下:
The _CrtIsValidHeapPointer function is used to ensure that a specific memory address is within the local heap. The local heap refers to the heap created and managed by a particular instance of the C run-time library. If a dynamic-link library (DLL) contains a static link to the run-time library, it has its own instance of the run-time heap, and therefore its own heap, independent of the application's local heap.

4.2结论

.使用Hoard后,内存操作速度提高了,对内存峰值的要求降低了.

5.发布

发布时需要增加winhoard.dll



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值