Path: blob/master/libs/vkd3d/include/private/vkd3d_memory.h
4393 views
/*1* Copyright 2016 Józef Kucia for CodeWeavers2*3* This library is free software; you can redistribute it and/or4* modify it under the terms of the GNU Lesser General Public5* License as published by the Free Software Foundation; either6* version 2.1 of the License, or (at your option) any later version.7*8* This library is distributed in the hope that it will be useful,9* but WITHOUT ANY WARRANTY; without even the implied warranty of10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU11* Lesser General Public License for more details.12*13* You should have received a copy of the GNU Lesser General Public14* License along with this library; if not, write to the Free Software15* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA16*/1718#ifndef __VKD3D_MEMORY_H19#define __VKD3D_MEMORY_H2021#include <stdbool.h>22#include <stdlib.h>23#include <string.h>2425#include "vkd3d_common.h"2627static inline void *vkd3d_malloc(size_t size)28{29void *ptr;30if (!(ptr = malloc(size)))31ERR("Out of memory.\n");32return ptr;33}3435static inline void *vkd3d_realloc(void *ptr, size_t size)36{37if (!(ptr = realloc(ptr, size)))38ERR("Out of memory, size %zu.\n", size);39return ptr;40}4142static inline void *vkd3d_calloc(size_t count, size_t size)43{44void *ptr;45VKD3D_ASSERT(!size || count <= ~(size_t)0 / size);46if (!(ptr = calloc(count, size)))47ERR("Out of memory.\n");48return ptr;49}5051static inline void vkd3d_free(void *ptr)52{53free(ptr);54}5556static inline char *vkd3d_strdup(const char *string)57{58size_t len = strlen(string) + 1;59char *ptr;6061if ((ptr = vkd3d_malloc(len)))62memcpy(ptr, string, len);63return ptr;64}6566static inline void *vkd3d_memdup(const void *mem, size_t size)67{68void *ptr;6970if ((ptr = vkd3d_malloc(size)))71memcpy(ptr, mem, size);72return ptr;73}7475bool vkd3d_array_reserve(void **elements, size_t *capacity, size_t element_count, size_t element_size);7677#endif /* __VKD3D_MEMORY_H */787980