PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
recycle.h
1
/*
2
--------------------------------------------------------------------
3
By Bob Jenkins, September 1996. recycle.h
4
You may use this code in any way you wish, and it is free. No warranty.
5
6
This manages memory for commonly-allocated structures.
7
It allocates RESTART to REMAX items at a time.
8
Timings have shown that, if malloc is used for every new structure,
9
malloc will consume about 90% of the time in a program. This
10
module cuts down the number of mallocs by an order of magnitude.
11
This also decreases memory fragmentation, and freeing all structures
12
only requires freeing the root.
13
--------------------------------------------------------------------
14
*/
15
16
#ifndef STANDARD
17
#include "standard.h"
18
#endif
19
20
#ifndef RECYCLE
21
#define RECYCLE
22
23
#ifdef __cplusplus
24
extern
"C"
{
25
#endif
26
27
#define RESTART 0
28
#define REMAX 32000
29
30
struct
recycle
31
{
32
struct
recycle
*next;
33
};
34
typedef
struct
recycle
recycle
;
35
36
struct
reroot
37
{
38
struct
recycle
*list;
/* list of malloced blocks */
39
struct
recycle
*trash;
/* list of deleted items */
40
size_t
size;
/* size of an item */
41
size_t
logsize;
/* log_2 of number of items in a block */
42
word numleft;
/* number of bytes left in this block */
43
};
44
typedef
struct
reroot
reroot
;
45
46
/* make a new recycling root */
47
reroot
*remkroot(
/*_ size_t mysize _*/
);
48
49
/* free a recycling root and all the items it has made */
50
void
refree(
/*_ struct reroot *r _*/
);
51
52
/* get a new (cleared) item from the root */
53
#define renew(r) ((r)->numleft ? \
54
(((char *)((r)->list+1))+((r)->numleft-=(r)->size)) : renewx(r))
55
56
char
*renewx(
/*_ struct reroot *r _*/
);
57
58
/* delete an item; let the root recycle it */
59
/* void redel(/o_ struct reroot *r, struct recycle *item _o/); */
60
#define redel(root,item) { \
61
((recycle *)item)->next=(root)->trash; \
62
(root)->trash=(recycle *)(item); \
63
}
64
65
/* malloc, but exit program if no joy */
66
/* use plain free() to free memory allocated by remalloc() */
67
char
*remalloc(
/*_ size_t len _*/
);
68
69
#ifdef __cplusplus
70
}
71
#endif
72
73
#endif
/* RECYCLE */
recycle
Definition
recycle.h:31
reroot
Definition
recycle.h:37
ee
erl
include
recycle.h
Generated on Thu Nov 14 2024 05:25:24 for PS2SDK by
1.9.8