NetSurf
memory.h
Go to the documentation of this file.
1/*
2 * Copyright 2016 Chris Young <chris@unsatisfactorysoftware.co.uk>
3 *
4 * This file is part of NetSurf, http://www.netsurf-browser.org/
5 *
6 * NetSurf is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * NetSurf is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef AMIGA_MEMORY_H
20#define AMIGA_MEMORY_H
21
22#include <exec/types.h>
23
24/* Alloc/free chip memory */
25#ifdef __amigaos4__
26#define ami_memory_chip_alloc(s) malloc(s)
27#define ami_memory_chip_free(p) free(p)
28#else
29#define ami_memory_chip_alloc(s) AllocVec(s, MEMF_CHIP)
30#define ami_memory_chip_free(p) FreeVec(p)
31#endif
32
33/* Alloc/free a block cleared to non-zero */
34#ifdef __amigaos4__
35#define ami_memory_clear_alloc(s,v) AllocVecTags(s, AVT_ClearWithValue, v, TAG_DONE)
36#define ami_memory_clear_free(p) FreeVec(p)
37#else
38void *ami_memory_clear_alloc(size_t size, UBYTE value);
39#define ami_memory_clear_free(p) free(p)
40#endif
41
42/* Itempool cross-compatibility */
43#ifdef __amigaos4__
44#define ami_memory_itempool_create(s) AllocSysObjectTags(ASOT_ITEMPOOL, \
45 ASOITEM_MFlags, MEMF_PRIVATE, \
46 ASOITEM_ItemSize, s, \
47 ASOITEM_GCPolicy, ITEMGC_AFTERCOUNT, \
48 ASOITEM_GCParameter, 100, \
49 TAG_DONE)
50#define ami_memory_itempool_delete(p) FreeSysObject(ASOT_ITEMPOOL, p)
51#define ami_memory_itempool_alloc(p,s) ItemPoolAlloc(p)
52#define ami_memory_itempool_free(p,i,s) ItemPoolFree(p,i)
53#else
54#define ami_memory_itempool_create(s) ((APTR)1)
55#define ami_memory_itempool_delete(p) ((void)0)
56#define ami_memory_itempool_alloc(p,s) malloc(s)
57#define ami_memory_itempool_free(p,i,s) free(i)
58#endif
59
60/* clib2 slab allocator */
61#ifndef __amigaos4__
62void ami_memory_slab_dump(BPTR fh);
63struct Interrupt *ami_memory_init(void);
64void ami_memory_fini(struct Interrupt *memhandler);
65#endif
66
67#endif //AMIGA_MEMORY_H
68
void * ami_memory_clear_alloc(size_t size, UBYTE value)
Definition: memory.c:42
void ami_memory_fini(struct Interrupt *memhandler)
Definition: memory.c:179
void ami_memory_slab_dump(BPTR fh)
Definition: memory.c:122
struct Interrupt * ami_memory_init(void)
Definition: memory.c:165