You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
4.1KB

  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. /**
  21. * @file libavutil/mem.h
  22. * memory handling functions
  23. */
  24. #ifndef AVUTIL_MEM_H
  25. #define AVUTIL_MEM_H
  26. #include "common.h"
  27. #if defined(__ICC) || defined(__SUNPRO_C)
  28. #define DECLARE_ALIGNED(n,t,v) t v __attribute__ ((aligned (n)))
  29. #define DECLARE_ASM_CONST(n,t,v) const t __attribute__ ((aligned (n))) v
  30. #elif defined(__GNUC__)
  31. #define DECLARE_ALIGNED(n,t,v) t v __attribute__ ((aligned (n)))
  32. #define DECLARE_ASM_CONST(n,t,v) static const t v attribute_used __attribute__ ((aligned (n)))
  33. #elif defined(_MSC_VER)
  34. #define DECLARE_ALIGNED(n,t,v) __declspec(align(n)) t v
  35. #define DECLARE_ASM_CONST(n,t,v) __declspec(align(n)) static const t v
  36. #else
  37. #define DECLARE_ALIGNED(n,t,v) t v
  38. #define DECLARE_ASM_CONST(n,t,v) static const t v
  39. #endif
  40. #if AV_GCC_VERSION_AT_LEAST(3,1)
  41. #define av_malloc_attrib __attribute__((__malloc__))
  42. #else
  43. #define av_malloc_attrib
  44. #endif
  45. #if (!defined(__ICC) || __ICC > 1110) && AV_GCC_VERSION_AT_LEAST(4,3)
  46. #define av_alloc_size(n) __attribute__((alloc_size(n)))
  47. #else
  48. #define av_alloc_size(n)
  49. #endif
  50. /**
  51. * Allocates a block of size bytes with alignment suitable for all
  52. * memory accesses (including vectors if available on the CPU).
  53. * @param size Size in bytes for the memory block to be allocated.
  54. * @return Pointer to the allocated block, NULL if the block cannot
  55. * be allocated.
  56. * @see av_mallocz()
  57. */
  58. void *av_malloc(unsigned int size) av_malloc_attrib av_alloc_size(1);
  59. /**
  60. * Allocates or reallocates a block of memory.
  61. * If ptr is NULL and size > 0, allocates a new block. If \p
  62. * size is zero, frees the memory block pointed to by ptr.
  63. * @param size Size in bytes for the memory block to be allocated or
  64. * reallocated.
  65. * @param ptr Pointer to a memory block already allocated with
  66. * av_malloc(z)() or av_realloc() or NULL.
  67. * @return Pointer to a newly reallocated block or NULL if the block
  68. * cannot be reallocated or the function is used to free the memory block.
  69. * @see av_fast_realloc()
  70. */
  71. void *av_realloc(void *ptr, unsigned int size) av_alloc_size(2);
  72. /**
  73. * Frees a memory block which has been allocated with av_malloc(z)() or
  74. * av_realloc().
  75. * @param ptr Pointer to the memory block which should be freed.
  76. * @note ptr = NULL is explicitly allowed.
  77. * @note It is recommended that you use av_freep() instead.
  78. * @see av_freep()
  79. */
  80. void av_free(void *ptr);
  81. /**
  82. * Allocates a block of size bytes with alignment suitable for all
  83. * memory accesses (including vectors if available on the CPU) and
  84. * zeroes all the bytes of the block.
  85. * @param size Size in bytes for the memory block to be allocated.
  86. * @return Pointer to the allocated block, NULL if it cannot be allocated.
  87. * @see av_malloc()
  88. */
  89. void *av_mallocz(unsigned int size) av_malloc_attrib av_alloc_size(1);
  90. /**
  91. * Duplicates the string s.
  92. * @param s string to be duplicated
  93. * @return Pointer to a newly allocated string containing a
  94. * copy of s or NULL if the string cannot be allocated.
  95. */
  96. char *av_strdup(const char *s) av_malloc_attrib;
  97. /**
  98. * Frees a memory block which has been allocated with av_malloc(z)() or
  99. * av_realloc() and set the pointer pointing to it to NULL.
  100. * @param ptr Pointer to the pointer to the memory block which should
  101. * be freed.
  102. * @see av_free()
  103. */
  104. void av_freep(void *ptr);
  105. #endif /* AVUTIL_MEM_H */