Skip to content

Commit

Permalink
Add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
anydream committed Sep 27, 2017
1 parent 500f65a commit 471ad49
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
1 change: 1 addition & 0 deletions tcmalloc_nohook/Config.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<AdditionalIncludeDirectories>../src/;../src/windows;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<MinimalRebuild>false</MinimalRebuild>
<PreprocessorDefinitions>PERFTOOLS_DLL_DECL=;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
</ItemDefinitionGroup>
<ItemGroup />
Expand Down
35 changes: 33 additions & 2 deletions tcmalloc_nohook/main.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,40 @@
#include <string.h>
#include <stdio.h>
#include <time.h>

#if 1
#include <gperftools/tcmalloc.h>
#define ALLOC tc_malloc
#define FREE tc_free
#else
#include <stdlib.h>
#define ALLOC malloc
#define FREE free
#endif

int main()
{
void *p = tc_malloc(256);
tc_free(p);
const char checkbuf[256] = { 1, 2, 3, 4 };

auto stt = clock();
size_t loops = 0;
for (;;)
{
void *p = ALLOC(sizeof(checkbuf));
memcpy(p, checkbuf, sizeof(checkbuf));
if (memcmp(p, checkbuf, sizeof(checkbuf)) != 0)
{
printf("Fail!\n");
break;
}
FREE(p);
++loops;

auto cut = clock();
if (cut - stt >= 5000)
break;
}
printf("Loops: %u\n", loops);

return 0;
}

0 comments on commit 471ad49

Please sign in to comment.