1 /* Copyright (c) 2020-2021 The Khronos Group Inc.
2 * Copyright (c) 2020-2021 LunarG, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * Author: Jeremy Gebben <jeremyg@lunarg.com>
17 */
18 #include "allocator.h"
19 #include <cstdlib>
20
21 namespace extension_layer {
22 // currently none of the extension layers have special alignment requirements so we just use malloc / free.
DefaultAlloc(void *,size_t size,size_t alignment,VkSystemAllocationScope)23 static VKAPI_ATTR void* VKAPI_CALL DefaultAlloc(void*, size_t size, size_t alignment, VkSystemAllocationScope) {
24 return std::malloc(size);
25 }
26
DefaultFree(void *,void * pMem)27 static VKAPI_ATTR void VKAPI_CALL DefaultFree(void*, void* pMem) { std::free(pMem); }
28
DefaultRealloc(void *,void * pOriginal,size_t size,size_t alignment,VkSystemAllocationScope)29 static VKAPI_ATTR void* VKAPI_CALL DefaultRealloc(void*, void* pOriginal, size_t size, size_t alignment, VkSystemAllocationScope) {
30 return std::realloc(pOriginal, size);
31 }
32
33 const VkAllocationCallbacks kDefaultAllocator = {
34 nullptr, DefaultAlloc, DefaultRealloc, DefaultFree, nullptr, nullptr,
35 };
36
37 } // namespace extension_layer
38