1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
6 #include "hostallocator.h"
8 HostAllocator HostAllocator::s_hostAllocator;
10 void* HostAllocator::Alloc(size_t size)
12 assert(g_jitHost != nullptr);
13 return g_jitHost->allocateMemory(size, false);
16 void* HostAllocator::ArrayAlloc(size_t elemSize, size_t numElems)
18 assert(g_jitHost != nullptr);
20 ClrSafeInt<size_t> safeElemSize(elemSize);
21 ClrSafeInt<size_t> safeNumElems(numElems);
22 ClrSafeInt<size_t> size = safeElemSize * safeNumElems;
23 if (size.IsOverflow())
28 return g_jitHost->allocateMemory(size.Value(), false);
31 void HostAllocator::Free(void* p)
33 assert(g_jitHost != nullptr);
34 g_jitHost->freeMemory(p, false);
37 HostAllocator* HostAllocator::getHostAllocator()
39 return &s_hostAllocator;