tcmalloc MT版本

I wanted to post a little information about some changes that I'm  working on finishing up for the windows version of tcmalloc. If  you've ever hadtrouble overriding malloc/free on windows, you might  find this useful. 


With Chrome, we wanted to override the default C runtime allocators  with TCMalloc. Chrome links the C runtime statically (/MT) in  VS2005. Unfortunately, VS2005 does not have a static mechanism to  override all allocators. This sounds easy, but it is not - VS2005 and  VS2008 both use C runtimes with internal functions that cannot be  overridden. We also didn't like the runtime patching approach which  tcmalloc currently uses. So, to get static linkage to work, we take  the C runtime library from Microsoft and remove all heap allocators  from it using the LIB.EXE tool. We then implement stub functions for  the non-overridable functions in the C runtime and manually link  Chrome to use the new library. 


If you want to do this too, here are the steps: 


Steps 
1) Create a slimmed down version of the C Runtime Library. The C  Runtime Library ships with VS2005 in $VCInstallDir\lib\libcmt.lib. We  use the script below to do this. 
2) In TCMalloc's config.h, define WIN32_OVERRIDE_ALLOCATORS 
3) Modify your DLL or EXE build with the following: 
a) link in tcmalloc.lib by adding a Project Dependency to it. 
b) in Properties -> Linker -> Input, set "Ignore Specific Library"  to "libcmt.lib" 
c) in Properties -> Linker -> Input, add "mylibcmt.lib" to the  "Additional Dependencies" line. 


SLIM_CRT.BAT 
REM 
REM This script takes libcmt.lib for VS2005 and removes the allocation 
related 
REM functions from it. 
REM 
REM Usage: prep_libcmt.bat <VCInstallDir> <OutputFile> 
REM 
REM VCInstallDir is the path where VC is installed, typically: 
REM C:\Program Files\Microsoft Visual Studio 8\VC\ 
REM 
REM OutputFile is the directory where the modified libcmt file should 
be stored. 
REM 


SET LIBCMT=%1lib\libcmt.lib 
SET LIBCMTPDB=%1lib\libcmt.pdb 
SET OUTDIR=%2 
SET OUTCMT=%2\libcmt.lib 


MKDIR %OUTDIR% 
COPY %LIBCMT% %OUTDIR% 
COPY %LIBCMTPDB% %OUTDIR% 
LIB /IGNORE:4006,4221 /REMOVE:build\intel\mt_obj\malloc.obj %OUTCMT% 
LIB /IGNORE:4006,4221 /REMOVE:build\intel\mt_obj\free.obj %OUTCMT% 
LIB /IGNORE:4006,4221 /REMOVE:build\intel\mt_obj\realloc.obj %OUTCMT% 
LIB /IGNORE:4006,4221 /REMOVE:build\intel\mt_obj\calloc.obj %OUTCMT% 
LIB /IGNORE:4006,4221 /REMOVE:build\intel\mt_obj\new.obj %OUTCMT% 
LIB /IGNORE:4006,4221 /REMOVE:build\intel\mt_obj\delete.obj %OUTCMT% 
LIB /IGNORE:4006,4221 /REMOVE:build\intel\mt_obj\new2.obj %OUTCMT% 
LIB /IGNORE:4006,4221 /REMOVE:build\intel\mt_obj\delete2.obj %OUTCMT% 
LIB /IGNORE:4006,4221 /REMOVE:build\intel\mt_obj\align.obj %OUTCMT% 
LIB /IGNORE:4006,4221 /REMOVE:build\intel\mt_obj\msize.obj %OUTCMT% 


LIB /IGNORE:4006,4221 /REMOVE:build\intel\mt_obj\heapinit.obj %OUTCMT% 
LIB /IGNORE:4006,4221 /REMOVE:build\intel\mt_obj\expand.obj %OUTCMT% 
LIB /IGNORE:4006,4221 /REMOVE:build\intel\mt_obj\heapchk.obj %OUTCMT% 
LIB /IGNORE:4006,4221 /REMOVE:build\intel\mt_obj\heapwalk.obj %OUTCMT% 
LIB /IGNORE:4006,4221 /REMOVE:build\intel\mt_obj\heapmin.obj %OUTCMT% 
LIB /IGNORE:4006,4221 /REMOVE:build\intel\mt_obj\sbheap.obj %OUTCMT% 
LIB /IGNORE:4006,4221 /REMOVE:build\intel\mt_obj\smalheap.obj %OUTCMT% 





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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值