2 * The UCW Library -- Resources for Memory Blocks
4 * (c) 2008 Martin Mares <mj@ucw.cz>
6 * This software may be freely distributed and used according to the terms
7 * of the GNU Lesser General Public License.
11 #include <ucw/resource.h>
19 size_t size; // Just for sake of readable resource dumps
23 mem_res_free(struct resource *r)
29 mem_res_dump(struct resource *r, uns indent UNUSED)
31 struct res_mem *rm = (struct res_mem *) r;
32 printf(" size=%zu, ptr=%p\n", rm->size, r->priv);
35 static const struct res_class mem_res_class = {
39 .res_size = sizeof(struct res_mem),
43 res_malloc(size_t size, struct resource **ptr)
45 void *p = xmalloc(size);
46 struct resource *r = res_new(&mem_res_class, p);
47 ((struct res_mem *) r) -> size = size;
54 res_malloc_zero(size_t size, struct resource **ptr)
56 void *p = res_malloc(size, ptr);
62 res_realloc(struct resource *r, size_t size)
64 struct res_mem *rm = (struct res_mem *) r;
65 r->priv = xrealloc(r->priv, size);
74 struct respool *rp = rp_new("test", NULL);
77 char *p = res_malloc(3, &r);
78 p[0] = p[1] = p[2] = 1;
80 p = res_realloc(r, 5);