mariadb/windows/os_malloc.c
Yoni Fogel 049c7625a3 Addresses #1765 Merge [12079] into main (pthreads-win32 for windows)
git-svn-id: file:///svn/toku/tokudb@12081 c7de825b-a66e-492c-adef-691d508d4ae1
2013-04-16 23:57:53 -04:00

53 lines
1 KiB
C

/* -*- mode: C; c-basic-offset: 4 -*- */
#ident "Copyright (c) 2007, 2008 Tokutek Inc. All rights reserved."
#include <toku_portability.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <errno.h>
static inline size_t resize(size_t n) {
if (n >= 1*1024*1024)
n = (n+7) & ~7; // round up to make windbg !heap happy
#define DO_PAD_64K 0
#if DO_PAD_64K
else if (64*1024 <= n && n < 1*1024*1024)
n = 1*1024*1024; // map anything >= 64K to 1M
#endif
#define DO_ROUND_POW2 1
#if DO_ROUND_POW2
else {
// make all buffers a power of 2 in size including the windows overhead
size_t r = 0;
size_t newn = 1<<r;
size_t overhead = 0x24;
n += overhead;
while (n > newn) {
r++;
newn = 1<<r;
}
n = newn - overhead;
}
#endif
return n;
}
void *
os_malloc(size_t size)
{
return malloc(resize(size));
}
void *
os_realloc(void *p, size_t size)
{
return realloc(p, resize(size));
}
void
os_free(void* p)
{
free(p);
}