1 /* libFLAC - Free Lossless Audio Codec library
2 * Copyright (C) 2001 Josh Coalson
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
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 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 #include "private/memory.h"
23 void *FLAC__memory_alloc_aligned(size_t bytes, void **aligned_address)
27 assert(0 != aligned_address);
29 #ifdef FLAC__ALIGN_MALLOC_DATA
30 /* align on 32-byte (256-bit) boundary */
32 *aligned_address = (void*)(((unsigned)x + 31) & -32);
40 bool FLAC__memory_alloc_aligned_int32_array(unsigned elements, int32 **unaligned_pointer, int32 **aligned_pointer)
42 int32 *pa, *pu; /* aligned pointer, unaligned pointer */
45 assert(0 != unaligned_pointer);
46 assert(0 != aligned_pointer);
47 assert(unaligned_pointer != aligned_pointer);
49 pu = (int32*)FLAC__memory_alloc_aligned(sizeof(int32) * elements, (void*)&pa);
54 if(*unaligned_pointer != 0)
55 free(*unaligned_pointer);
56 *unaligned_pointer = pu;
57 *aligned_pointer = pa;
62 bool FLAC__memory_alloc_aligned_uint32_array(unsigned elements, uint32 **unaligned_pointer, uint32 **aligned_pointer)
64 uint32 *pa, *pu; /* aligned pointer, unaligned pointer */
67 assert(0 != unaligned_pointer);
68 assert(0 != aligned_pointer);
69 assert(unaligned_pointer != aligned_pointer);
71 pu = (uint32*)FLAC__memory_alloc_aligned(sizeof(uint32) * elements, (void*)&pa);
76 if(*unaligned_pointer != 0)
77 free(*unaligned_pointer);
78 *unaligned_pointer = pu;
79 *aligned_pointer = pa;
84 bool FLAC__memory_alloc_aligned_unsigned_array(unsigned elements, unsigned **unaligned_pointer, unsigned **aligned_pointer)
86 unsigned *pa, *pu; /* aligned pointer, unaligned pointer */
89 assert(0 != unaligned_pointer);
90 assert(0 != aligned_pointer);
91 assert(unaligned_pointer != aligned_pointer);
93 pu = (unsigned*)FLAC__memory_alloc_aligned(sizeof(unsigned) * elements, (void*)&pa);
98 if(*unaligned_pointer != 0)
99 free(*unaligned_pointer);
100 *unaligned_pointer = pu;
101 *aligned_pointer = pa;
106 bool FLAC__memory_alloc_aligned_real_array(unsigned elements, real **unaligned_pointer, real **aligned_pointer)
108 real *pa, *pu; /* aligned pointer, unaligned pointer */
110 assert(elements > 0);
111 assert(0 != unaligned_pointer);
112 assert(0 != aligned_pointer);
113 assert(unaligned_pointer != aligned_pointer);
115 pu = (real*)FLAC__memory_alloc_aligned(sizeof(real) * elements, (void*)&pa);
120 if(*unaligned_pointer != 0)
121 free(*unaligned_pointer);
122 *unaligned_pointer = pu;
123 *aligned_pointer = pa;