spandsp  3.0.0
alloc.h
Go to the documentation of this file.
1 /*
2  * SpanDSP - a series of DSP components for telephony
3  *
4  * alloc.h - memory allocation handling.
5  *
6  * Written by Steve Underwood <steveu@coppice.org>
7  *
8  * Copyright (C) 2013 Steve Underwood
9  *
10  * All rights reserved.
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU Lesser General Public License version 2.1,
14  * as published by the Free Software Foundation.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public
22  * License along with this program; if not, write to the Free Software
23  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24  */
25 
26 /*! \file */
27 
28 #if !defined(_SPANDSP_ALLOC_H_)
29 #define _SPANDSP_ALLOC_H_
30 
31 /* Notes:
32  - Most platforms don't have an aligned realloc function, so we don't try to
33  support an aligned realloc on any platform.
34  - Some platforms use a special free function for memory which was allocated
35  by alligned allocation functions. We use a separate aligned_free function
36  on all platforms, for compatibility, even though it may simply reduce to
37  free().
38  */
39 
40 typedef void *(*span_aligned_alloc_t)(size_t alignment, size_t size);
41 typedef void (*span_aligned_free_t)(void *ptr);
42 typedef void *(*span_alloc_t)(size_t size);
43 typedef void *(*span_realloc_t)(void *ptr, size_t size);
44 typedef void (*span_free_t)(void *ptr);
45 
46 #if defined(__cplusplus)
47 extern "C"
48 {
49 #endif
50 
51 /* Allocate size bytes allocated to ALIGNMENT bytes. */
52 SPAN_DECLARE(void *) span_aligned_alloc(size_t alignment, size_t size);
53 
54 /* Free a block allocated by span_aligned_alloc, or span_aligned_realloc. */
55 SPAN_DECLARE(void) span_aligned_free(void *ptr);
56 
57 /* Allocate size bytes of memory. */
58 SPAN_DECLARE(void *) span_alloc(size_t size);
59 
60 /* Re-allocate the previously allocated block in ptr, making the new block size bytes long. */
61 SPAN_DECLARE(void *) span_realloc(void *ptr, size_t size);
62 
63 /* Free a block allocated by span_alloc or span_realloc. */
64 SPAN_DECLARE(void) span_free(void *ptr);
65 
66 SPAN_DECLARE(int) span_mem_allocators(span_alloc_t custom_alloc,
67  span_realloc_t custom_realloc,
68  span_free_t custom_free,
69  span_aligned_alloc_t custom_aligned_alloc,
70  span_aligned_free_t custom_aligned_free);
71 
72 #if defined(__cplusplus)
73 }
74 #endif
75 
76 #endif
77 /*- End of file ------------------------------------------------------------*/