World of Might and Magic  0.2.0
Open reimplementation of Might and Magic 6 7 8 game engine
mem.h
См. документацию.
1 /*
2  * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
27 #ifndef AVUTIL_MEM_H
28 #define AVUTIL_MEM_H
29 
30 #include <limits.h>
31 #include <stdint.h>
32 
33 #include "attributes.h"
34 #include "error.h"
35 #include "avutil.h"
36 
103 #if defined(__INTEL_COMPILER) && __INTEL_COMPILER < 1110 || defined(__SUNPRO_C)
104  #define DECLARE_ALIGNED(n,t,v) t __attribute__ ((aligned (n))) v
105  #define DECLARE_ASM_ALIGNED(n,t,v) t __attribute__ ((aligned (n))) v
106  #define DECLARE_ASM_CONST(n,t,v) const t __attribute__ ((aligned (n))) v
107 #elif defined(__DJGPP__)
108  #define DECLARE_ALIGNED(n,t,v) t __attribute__ ((aligned (FFMIN(n, 16)))) v
109  #define DECLARE_ASM_ALIGNED(n,t,v) t av_used __attribute__ ((aligned (FFMIN(n, 16)))) v
110  #define DECLARE_ASM_CONST(n,t,v) static const t av_used __attribute__ ((aligned (FFMIN(n, 16)))) v
111 #elif defined(__GNUC__) || defined(__clang__)
112  #define DECLARE_ALIGNED(n,t,v) t __attribute__ ((aligned (n))) v
113  #define DECLARE_ASM_ALIGNED(n,t,v) t av_used __attribute__ ((aligned (n))) v
114  #define DECLARE_ASM_CONST(n,t,v) static const t av_used __attribute__ ((aligned (n))) v
115 #elif defined(_MSC_VER)
116  #define DECLARE_ALIGNED(n,t,v) __declspec(align(n)) t v
117  #define DECLARE_ASM_ALIGNED(n,t,v) __declspec(align(n)) t v
118  #define DECLARE_ASM_CONST(n,t,v) __declspec(align(n)) static const t v
119 #else
120  #define DECLARE_ALIGNED(n,t,v) t v
121  #define DECLARE_ASM_ALIGNED(n,t,v) t v
122  #define DECLARE_ASM_CONST(n,t,v) static const t v
123 #endif
124 
145 #if AV_GCC_VERSION_AT_LEAST(3,1)
146  #define av_malloc_attrib __attribute__((__malloc__))
147 #else
148  #define av_malloc_attrib
149 #endif
150 
166 #if AV_GCC_VERSION_AT_LEAST(4,3)
167  #define av_alloc_size(...) __attribute__((alloc_size(__VA_ARGS__)))
168 #else
169  #define av_alloc_size(...)
170 #endif
171 
196 void *av_malloc(size_t size) av_malloc_attrib av_alloc_size(1);
197 
207 void *av_mallocz(size_t size) av_malloc_attrib av_alloc_size(1);
208 
220 av_alloc_size(1, 2) void *av_malloc_array(size_t nmemb, size_t size);
221 
235 av_alloc_size(1, 2) void *av_mallocz_array(size_t nmemb, size_t size);
236 
242 void *av_calloc(size_t nmemb, size_t size) av_malloc_attrib;
243 
264 void *av_realloc(void *ptr, size_t size) av_alloc_size(2);
265 
285 av_warn_unused_result
286 int av_reallocp(void *ptr, size_t size);
287 
303 void *av_realloc_f(void *ptr, size_t nelem, size_t elsize);
304 
323 av_alloc_size(2, 3) void *av_realloc_array(void *ptr, size_t nmemb, size_t size);
324 
342 int av_reallocp_array(void *ptr, size_t nmemb, size_t size);
343 
376 void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size);
377 
407 void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size);
408 
427 void av_fast_mallocz(void *ptr, unsigned int *size, size_t min_size);
428 
440 void av_free(void *ptr);
441 
463 void av_freep(void *ptr);
464 
473 char *av_strdup(const char *s) av_malloc_attrib;
474 
484 char *av_strndup(const char *s, size_t len) av_malloc_attrib;
485 
494 void *av_memdup(const void *p, size_t size);
495 
507 void av_memcpy_backptr(uint8_t *dst, int back, int cnt);
508 
609 void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem);
610 
621 av_warn_unused_result
622 int av_dynarray_add_nofree(void *tab_ptr, int *nb_ptr, void *elem);
623 
647 void *av_dynarray2_add(void **tab_ptr, int *nb_ptr, size_t elem_size,
648  const uint8_t *elem_data);
649 
669 static inline int av_size_mult(size_t a, size_t b, size_t *r)
670 {
671  size_t t = a * b;
672  /* Hack inspired from glibc: don't try the division if nelem and elsize
673  * are both less than sqrt(SIZE_MAX). */
674  if ((a | b) >= ((size_t)1 << (sizeof(size_t) * 4)) && a && t / a != b)
675  return AVERROR(EINVAL);
676  *r = t;
677  return 0;
678 }
679 
693 void av_max_alloc(size_t max);
694 
700 #endif /* AVUTIL_MEM_H */
s
GLdouble s
Definition: SDL_opengl.h:2063
av_malloc
void * av_malloc(size_t size) av_malloc_attrib av_alloc_size(1)
av_dynarray2_add
void * av_dynarray2_add(void **tab_ptr, int *nb_ptr, size_t elem_size, const uint8_t *elem_data)
av_memdup
void * av_memdup(const void *p, size_t size)
av_max_alloc
void av_max_alloc(size_t max)
av_realloc_f
void * av_realloc_f(void *ptr, size_t nelem, size_t elsize)
av_realloc
void * av_realloc(void *ptr, size_t size) av_alloc_size(2)
av_memcpy_backptr
void av_memcpy_backptr(uint8_t *dst, int back, int cnt)
av_fast_realloc
void * av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
av_freep
void av_freep(void *ptr)
av_size_mult
static int av_size_mult(size_t a, size_t b, size_t *r)
Definition: mem.h:669
len
GLenum GLsizei len
Definition: SDL_opengl_glext.h:2929
p
GLfloat GLfloat p
Definition: SDL_opengl_glext.h:11093
av_fast_mallocz
void av_fast_mallocz(void *ptr, unsigned int *size, size_t min_size)
error.h
av_mallocz
void * av_mallocz(size_t size) av_malloc_attrib av_alloc_size(1)
av_dynarray_add
void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem)
av_reallocp
av_warn_unused_result int av_reallocp(void *ptr, size_t size)
dst
GLenum GLenum dst
Definition: SDL_opengl_glext.h:1740
av_reallocp_array
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
attributes.h
t
GLdouble GLdouble t
Definition: SDL_opengl.h:2071
nmemb
size_t nmemb
Definition: mem.h:323
void
typedef void(SDLCALL *SDL_AudioFilter)(struct SDL_AudioCVT *cvt
uint8_t
unsigned __int8 uint8_t
Definition: SDL_config.h:35
b
GLboolean GLboolean GLboolean b
Definition: SDL_opengl_glext.h:1112
r
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
av_free
void av_free(void *ptr)
av_dynarray_add_nofree
av_warn_unused_result int av_dynarray_add_nofree(void *tab_ptr, int *nb_ptr, void *elem)
av_calloc
void * av_calloc(size_t nmemb, size_t size) av_malloc_attrib
a
GLboolean GLboolean GLboolean GLboolean a
Definition: SDL_opengl_glext.h:1112
av_strdup
char * av_strdup(const char *s) av_malloc_attrib
avutil.h
av_alloc_size
av_alloc_size(1, 2) void *av_malloc_array(size_t nmemb
size
GLsizeiptr size
Definition: SDL_opengl_glext.h:540
av_fast_malloc
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
av_strndup
char * av_strndup(const char *s, size_t len) av_malloc_attrib