]>
code.delx.au - pulseaudio/blob - polyp/memblock.c
0571f5dae87859137c18f6bb20cdbf764447a8f2
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
34 static unsigned memblock_count
= 0, memblock_total
= 0;
36 struct pa_memblock
*pa_memblock_new(size_t length
) {
37 struct pa_memblock
*b
= pa_xmalloc(sizeof(struct pa_memblock
)+length
);
38 b
->type
= PA_MEMBLOCK_APPENDED
;
43 memblock_total
+= length
;
47 struct pa_memblock
*pa_memblock_new_fixed(void *d
, size_t length
) {
48 struct pa_memblock
*b
= pa_xmalloc(sizeof(struct pa_memblock
));
49 b
->type
= PA_MEMBLOCK_FIXED
;
54 memblock_total
+= length
;
58 struct pa_memblock
*pa_memblock_new_dynamic(void *d
, size_t length
) {
59 struct pa_memblock
*b
= pa_xmalloc(sizeof(struct pa_memblock
));
60 b
->type
= PA_MEMBLOCK_DYNAMIC
;
65 memblock_total
+= length
;
69 struct pa_memblock
* pa_memblock_ref(struct pa_memblock
*b
) {
70 assert(b
&& b
->ref
>= 1);
75 void pa_memblock_unref(struct pa_memblock
*b
) {
76 assert(b
&& b
->ref
>= 1);
80 if (b
->type
== PA_MEMBLOCK_DYNAMIC
)
84 memblock_total
-= b
->length
;
90 void pa_memblock_unref_fixed(struct pa_memblock
*b
) {
93 assert(b
&& b
->ref
>= 1);
99 d
= pa_xmalloc(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
;