Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/libs/vkd3d/include/private/vkd3d_memory.h
4393 views
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
28
static 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
36
static 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
43
static 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
52
static inline void vkd3d_free(void *ptr)
53
{
54
free(ptr);
55
}
56
57
static 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
67
static 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
76
bool vkd3d_array_reserve(void **elements, size_t *capacity, size_t element_count, size_t element_size);
77
78
#endif /* __VKD3D_MEMORY_H */
79
80