Signed-off-by: Sven Eckelmann sven.eckelmann@gmx.de --- batman/allocate.c | 24 ++++++++++++++++++++---- batman/batman.h | 2 ++ batman/bitarray.h | 4 +--- 3 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/batman/allocate.c b/batman/allocate.c index a779504..5e28c71 100644 --- a/batman/allocate.c +++ b/batman/allocate.c @@ -68,16 +68,32 @@ struct memoryUsage
static size_t getHeaderPad() { - size_t pad = sizeof(uintmax_t) - (sizeof(struct chunkHeader) % sizeof(uintmax_t)); - if (pad == sizeof(uintmax_t)) + size_t alignwith, pad; + + if (sizeof(TYPE_OF_WORD) > sizeof(void*)) + alignwith = sizeof(TYPE_OF_WORD); + else + alignwith = sizeof(void*); + + pad = alignwith - (sizeof(struct chunkHeader) % alignwith); + + if (pad == alignwith) return 0; else return pad; }
static size_t getTrailerPad(size_t length) { - size_t pad = sizeof(uintmax_t) - (length % sizeof(uintmax_t)); - if (pad == sizeof(uintmax_t)) + size_t alignwith, pad; + + if (sizeof(TYPE_OF_WORD) > sizeof(void*)) + alignwith = sizeof(TYPE_OF_WORD); + else + alignwith = sizeof(void*); + + pad = alignwith - (length % alignwith); + + if (pad == alignwith) return 0; else return pad; diff --git a/batman/batman.h b/batman/batman.h index c02ce8d..1cc5896 100644 --- a/batman/batman.h +++ b/batman/batman.h @@ -31,6 +31,8 @@ #include <stdint.h> #include <stdio.h>
+#define TYPE_OF_WORD uintmax_t /* you should choose something big, if you don't want to waste cpu */ + #include "list-batman.h" #include "bitarray.h" #include "hash.h" diff --git a/batman/bitarray.h b/batman/bitarray.h index 5472ef1..0bb0710 100644 --- a/batman/bitarray.h +++ b/batman/bitarray.h @@ -21,10 +21,8 @@
-#define TYPE_OF_WORD unsigned long /* you should choose something big, if you don't want to waste cpu */ -#define WORD_BIT_SIZE ( sizeof(TYPE_OF_WORD) * 8 ) #include "batman.h" - +#define WORD_BIT_SIZE ( sizeof(TYPE_OF_WORD) * 8 )
void bit_init( TYPE_OF_WORD *seq_bits );