aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yt/malloc/malloc.cpp
blob: 2455970b717684da4140f0daad030020764612e0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "malloc.h"

#include <util/system/compiler.h>
#include <util/system/platform.h>

#include <stdlib.h>

////////////////////////////////////////////////////////////////////////////////

Y_WEAK extern "C" size_t nallocx(size_t size, int /*flags*/) noexcept
{
    return size;
}

#ifndef _win_
Y_WEAK extern "C" size_t malloc_usable_size(void* /*ptr*/) noexcept
{
    return 0;
}
#endif

void* aligned_malloc(size_t size, size_t alignment)
{
#if defined(_win_)
    return _aligned_malloc(size, alignment);
#elif defined(_darwin_) || defined(_linux_)
    void* ptr = nullptr;
    ::posix_memalign(&ptr, alignment, size);
    return ptr;
#else
#   error Unsupported platform
#endif
}

////////////////////////////////////////////////////////////////////////////////