| 1 |
pippijn |
1.1 |
/* |
| 2 |
|
|
* Copyright © 2005 Atheme Development Group |
| 3 |
pippijn |
1.2 |
* Rights to this code are as documented in doc/pod/license.pod. |
| 4 |
pippijn |
1.1 |
* |
| 5 |
|
|
* Memory stuff. |
| 6 |
|
|
* |
| 7 |
pippijn |
1.4 |
* $Id: atheme_memory.h,v 1.3 2007-07-25 00:03:21 pippijn Exp $ |
| 8 |
pippijn |
1.1 |
*/ |
| 9 |
|
|
|
| 10 |
|
|
#ifndef __CLAROBASEMEMORY |
| 11 |
|
|
#define __CLAROBASEMEMORY |
| 12 |
|
|
|
| 13 |
|
|
E void *smalloc (size_t size); |
| 14 |
|
|
E void *scalloc (size_t elsize, size_t els); |
| 15 |
|
|
E void *srealloc (void *oldptr, size_t newsize); |
| 16 |
|
|
E char *sstrdup (const char *s); |
| 17 |
|
|
E char *sstrndup (const char *s, int len); |
| 18 |
|
|
|
| 19 |
pippijn |
1.3 |
// simple garbage collection for smalloc'ed blocks |
| 20 |
|
|
struct gc |
| 21 |
|
|
{ |
| 22 |
|
|
static void insert (void *ptr) |
| 23 |
|
|
{ |
| 24 |
|
|
mortals.push_back (ptr); |
| 25 |
|
|
} |
| 26 |
|
|
|
| 27 |
|
|
static void cleanup () |
| 28 |
|
|
{ |
| 29 |
|
|
while (!mortals.empty ()) |
| 30 |
|
|
{ |
| 31 |
|
|
free (mortals.back ()); |
| 32 |
|
|
mortals.pop_back (); |
| 33 |
|
|
} |
| 34 |
|
|
} |
| 35 |
|
|
|
| 36 |
|
|
private: |
| 37 |
|
|
static std::vector<void *> mortals; |
| 38 |
|
|
}; |
| 39 |
|
|
|
| 40 |
pippijn |
1.1 |
#endif |