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.

127 lines
4.4KB

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