MCPcopy Create free account
hub / github.com/catboost/catboost / LFPosixMemalign

Function LFPosixMemalign

library/cpp/lfalloc/lf_allocX64.h:1876–1914  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1874}
1875
1876static Y_FORCE_INLINE int LFPosixMemalign(void** memptr, size_t alignment, size_t size) {
1877 if (Y_UNLIKELY(alignment > 4096)) {
1878 const char* error = "Larger alignment are not guaranteed with this implementation\n";
1879#ifdef _win_
1880 OutputDebugStringA(error);
1881#endif
1882 NMalloc::AbortFromCorruptedAllocator(error);
1883 }
1884 size_t bigsize = size;
1885 if (bigsize <= alignment) {
1886 bigsize = alignment;
1887 } else if (bigsize < 2 * alignment) {
1888 bigsize = 2 * alignment;
1889 }
1890#if defined(LFALLOC_DBG)
1891 if (alignment > sizeof(TAllocHeader)) {
1892 bigsize += alignment;
1893 }
1894#endif
1895
1896 *memptr = LFAlloc(bigsize);
1897
1898#if defined(LFALLOC_DBG)
1899 if (alignment > sizeof(TAllocHeader)) {
1900 // memptr isn't aligned due to alloc header
1901 const auto* header = GetAllocHeader(*memptr);
1902 *memptr = (void*)((const char*) (*memptr) + alignment - sizeof(TAllocHeader));
1903
1904 // make fake header to retrieve original header ptr on dealloc
1905 auto* next = GetAllocHeader(*memptr);
1906 next->Tag = DBG_ALLOC_ALIGNED_TAG;
1907 next->Size = (uint64_t)header;
1908 next->Cookie = 0;
1909 }
1910#endif
1911
1912 Y_ASSERT_NOBT((intptr_t)*memptr % alignment == 0);
1913 return 0;
1914}
1915
1916static Y_FORCE_INLINE void* LFVAlloc(size_t size) {
1917 const size_t pg = N_PAGE_SIZE;

Callers 3

LFVAllocFunction · 0.85
posix_memalignFunction · 0.85
memalignFunction · 0.85

Calls 3

LFAllocFunction · 0.85
GetAllocHeaderFunction · 0.85

Tested by

no test coverage detected