ReactOS 0.4.17-dev-923-g4c9a150
vkd3d_memory.h
Go to the documentation of this file.
1/*
2 * Copyright 2016 Józef Kucia for CodeWeavers
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19#ifndef __VKD3D_MEMORY_H
20#define __VKD3D_MEMORY_H
21
22#include <stdbool.h>
23#include <stdlib.h>
24#include <string.h>
25
26#include "vkd3d_common.h"
27
28static inline void *vkd3d_malloc(size_t size)
29{
30 void *ptr;
31 if (!(ptr = malloc(size)))
32 ERR("Out of memory.\n");
33 return ptr;
34}
35
36static inline void *vkd3d_realloc(void *ptr, size_t size)
37{
38 if (!(ptr = realloc(ptr, size)))
39 ERR("Out of memory, size %zu.\n", size);
40 return ptr;
41}
42
43static inline void *vkd3d_calloc(size_t count, size_t size)
44{
45 void *ptr;
46 VKD3D_ASSERT(!size || count <= ~(size_t)0 / size);
47 if (!(ptr = calloc(count, size)))
48 ERR("Out of memory.\n");
49 return ptr;
50}
51
52static inline void vkd3d_free(void *ptr)
53{
54 free(ptr);
55}
56
57static inline char *vkd3d_strdup(const char *string)
58{
59 size_t len = strlen(string) + 1;
60 char *ptr;
61
62 if ((ptr = vkd3d_malloc(len)))
63 memcpy(ptr, string, len);
64 return ptr;
65}
66
67static inline void *vkd3d_memdup(const void *mem, size_t size)
68{
69 void *ptr;
70
71 if ((ptr = vkd3d_malloc(size)))
72 memcpy(ptr, mem, size);
73 return ptr;
74}
75
76bool vkd3d_array_reserve(void **elements, size_t *capacity, size_t element_count, size_t element_size);
77
78#endif /* __VKD3D_MEMORY_H */
#define ERR(fmt,...)
Definition: precomp.h:57
size_t const element_size
Definition: debug_heap.cpp:510
#define realloc
Definition: debug_ros.c:6
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
_ACRTIMP size_t __cdecl strlen(const char *)
Definition: string.c:1597
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLsizeiptr size
Definition: glext.h:5919
GLenum GLsizei len
Definition: glext.h:6722
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static PVOID ptr
Definition: dispmode.c:27
static ULONG ** element_count
Definition: exception.c:124
#define calloc
Definition: rosglue.h:14
Definition: mem.c:349
#define VKD3D_ASSERT(cond)
Definition: vkd3d_common.h:49
static void * vkd3d_calloc(size_t count, size_t size)
Definition: vkd3d_memory.h:43
static char * vkd3d_strdup(const char *string)
Definition: vkd3d_memory.h:57
static void * vkd3d_memdup(const void *mem, size_t size)
Definition: vkd3d_memory.h:67
static void * vkd3d_realloc(void *ptr, size_t size)
Definition: vkd3d_memory.h:36
static void vkd3d_free(void *ptr)
Definition: vkd3d_memory.h:52
static void * vkd3d_malloc(size_t size)
Definition: vkd3d_memory.h:28
bool vkd3d_array_reserve(void **elements, size_t *capacity, size_t element_count, size_t element_size)
Definition: memory.c:22