ps2sdk  1.1
A collection of Open Source libraries used for developing applications on Sony's PlayStation 2® (PS2).
recycle.c File Reference
#include <string.h>
#include <malloc.h>
#include "standard.h"
#include "recycle.h"
+ Include dependency graph for recycle.c:

Go to the source code of this file.

Functions

rerootremkroot (size_t size)
 
void refree (struct reroot *r)
 
char * renewx (struct reroot *r)
 
char * remalloc (size_t len)
 

Function Documentation

◆ refree()

void refree ( struct reroot r)

Definition at line 38 of file recycle.c.

40 {
41  recycle *temp;
42  if ((temp = r->list)) while (r->list)
43  {
44  temp = r->list->next;
45  free((char *)r->list);
46  r->list = temp;
47  }
48  free((char *)r);
49  return;
50 }
struct recycle * next
Definition: recycle.h:32
struct recycle * list
Definition: recycle.h:38

References reroot::list, and recycle::next.

◆ remalloc()

char* remalloc ( size_t  len)

Definition at line 76 of file recycle.c.

78 {
79  char *x = (char *)malloc(len);
80  if (!x)
81  {
82  //exit(SUCCESS); // let's just bug silently...
83  }
84  return x;
85 }
s32 x
Definition: libmouse.c:34

References x.

Referenced by remkroot(), and renewx().

◆ remkroot()

reroot* remkroot ( size_t  size)

Definition at line 26 of file recycle.c.

28 {
29  reroot *r = (reroot *)remalloc(sizeof(reroot));
30  r->list = (recycle *)0;
31  r->trash = (recycle *)0;
32  r->size = align(size);
33  r->logsize = RESTART;
34  r->numleft = 0;
35  return r;
36 }
s8 align[6]
Definition: libpad.c:230
char * remalloc(size_t len)
Definition: recycle.c:76
#define RESTART
Definition: recycle.h:27
Definition: recycle.h:37
size_t logsize
Definition: recycle.h:41
struct recycle * trash
Definition: recycle.h:39
word numleft
Definition: recycle.h:42
size_t size
Definition: recycle.h:40

References align, reroot::list, reroot::logsize, reroot::numleft, remalloc(), RESTART, reroot::size, and reroot::trash.

◆ renewx()

char* renewx ( struct reroot r)

Definition at line 53 of file recycle.c.

55 {
56  recycle *temp;
57  if (r->trash)
58  { /* pull a node off the trash heap */
59  temp = r->trash;
60  r->trash = temp->next;
61  (void)memset((void *)temp, 0, r->size);
62  }
63  else
64  { /* allocate a new block of nodes */
65  r->numleft = r->size*((ub4)1<<r->logsize);
66  if (r->numleft < REMAX) ++r->logsize;
67  temp = (recycle *)remalloc(sizeof(recycle) + r->numleft);
68  temp->next = r->list;
69  r->list = temp;
70  r->numleft-=r->size;
71  temp = (recycle *)((char *)(r->list+1)+r->numleft);
72  }
73  return (char *)temp;
74 }
#define REMAX
Definition: recycle.h:28
u32 ub4
Definition: standard.h:32

References reroot::list, reroot::logsize, recycle::next, reroot::numleft, remalloc(), REMAX, reroot::size, and reroot::trash.