mandelbrot

Mandelbrot viewer written in C and GLSL
git clone anongit@rnpnr.xyz:mandelbrot.git
Log | Files | Refs | Feed | LICENSE

util.c (604B)


      1 /* see LICENSE for licensing details */
      2 
      3 static void *
      4 mem_clear(u8 *p, u8 c, size len)
      5 {
      6 	while (len) p[--len] = c;
      7 	return p;
      8 }
      9 
     10 #define alloc(a, t, n) alloc_(a, sizeof(t), _Alignof(t), n)
     11 __attribute((malloc, alloc_size(4, 2), alloc_align(3)))
     12 static void *
     13 alloc_(Arena *a, size len, size align, size count)
     14 {
     15 	size padding   = -(uintptr_t)a->beg & (align - 1);
     16 	size available = a->end - a->beg - padding;
     17 	if (available < 0 || count > available / len) {
     18 		/* TODO: handle error */
     19 		u8 *t = 0; *t = 1;
     20 	}
     21 	void *p = a->beg + padding;
     22 	a->beg += count * len;
     23 	return mem_clear(p, 0, count * len);
     24 }