#ifndef DEBUG #define DEBUG #endif #include #include #include #include "ucore/utils.h" #include "../src/salloc.c" struct Foo { short s1; char b; short s2; int foo; char *data; char c; }; int main(int argc, char *argv[]) { size_t i; Chunk *c; SAlloc *s = uc_new_salloc(1023); printf("Alignof double %zu\n", __alignof__(double)); printf("Alignof void* %zu\n", __alignof__(void*)); printf("Alignof struct Foo %zu\n", __alignof__(struct Foo)); for (i = 0; i < 1013; i++) { uintptr_t p = (uintptr_t)uc_s_alloc(s, sizeof(double)*41); assert((p/__alignof__(double)) * __alignof__(double) == p); } c = s->first; while(c) { uintptr_t p = (uintptr_t)&c->data.data[0]; printf("Chunk data %p\n", &c->data.data[0]); c = c->next; assert((p/__alignof__(short)) * __alignof__(short) == p); assert((p/__alignof__(int)) * __alignof__(int) == p); assert((p/__alignof__(float)) * __alignof__(float) == p); assert((p/__alignof__(long long)) * __alignof__(long long) == p); assert((p/__alignof__(void*)) * __alignof__(void*) == p); assert((p/__alignof__(double)) * __alignof__(double) == p); } uc_free_salloc(s); s = uc_new_salloc(141); for (i = 0; i < 1013; i++) { uintptr_t p = (uintptr_t)uc_s_alloc(s, sizeof(struct Foo)); assert((p/__alignof__(struct Foo)) * __alignof__(struct Foo) == p); } uc_free_salloc(s); return 0; }