]>
code.delx.au - pulseaudio/blob - src/memblock.c
4 This file is part of polypaudio.
6 polypaudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published
8 by the Free Software Foundation; either version 2 of the License,
9 or (at your option) any later version.
11 polypaudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with polypaudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
33 static unsigned memblock_count
= 0, memblock_total
= 0;
35 struct pa_memblock
*pa_memblock_new(size_t length
) {
36 struct pa_memblock
*b
= malloc(sizeof(struct pa_memblock
)+length
);
37 b
->type
= PA_MEMBLOCK_APPENDED
;
42 memblock_total
+= length
;
46 struct pa_memblock
*pa_memblock_new_fixed(void *d
, size_t length
) {
47 struct pa_memblock
*b
= malloc(sizeof(struct pa_memblock
));
48 b
->type
= PA_MEMBLOCK_FIXED
;
53 memblock_total
+= length
;
57 struct pa_memblock
*pa_memblock_new_dynamic(void *d
, size_t length
) {
58 struct pa_memblock
*b
= malloc(sizeof(struct pa_memblock
));
59 b
->type
= PA_MEMBLOCK_DYNAMIC
;
64 memblock_total
+= length
;
68 struct pa_memblock
* pa_memblock_ref(struct pa_memblock
*b
) {
69 assert(b
&& b
->ref
>= 1);
74 void pa_memblock_unref(struct pa_memblock
*b
) {
75 assert(b
&& b
->ref
>= 1);
79 if (b
->type
== PA_MEMBLOCK_DYNAMIC
)
83 memblock_total
-= b
->length
;
89 void pa_memblock_unref_fixed(struct pa_memblock
*b
) {
92 assert(b
&& b
->ref
>= 1);
98 d
= malloc(b
->length
);
100 memcpy(d
, b
->data
, b
->length
);
102 b
->type
= PA_MEMBLOCK_DYNAMIC
;
107 unsigned pa_memblock_get_count(void) {
108 return memblock_count
;
111 unsigned pa_memblock_get_total(void) {
112 return memblock_total
;