Skip to content

Commit ad4d65c

Browse files
author
marek
committed
[batman] Make TYPE_OF_WORD the largest integral type
Signed-off-by: Sven Eckelmann <[email protected]> git-svn-id: http://downloads.open-mesh.org/svn/batman/trunk/batman@1280 45894c77-fb22-0410-b583-ff6e7d5dbf6c
1 parent 5f18ece commit ad4d65c

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

allocate.c

+20-4
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,32 @@ struct memoryUsage
6868

6969

7070
static size_t getHeaderPad() {
71-
size_t pad = sizeof(uintmax_t) - (sizeof(struct chunkHeader) % sizeof(uintmax_t));
72-
if (pad == sizeof(uintmax_t))
71+
size_t alignwith, pad;
72+
73+
if (sizeof(TYPE_OF_WORD) > sizeof(void*))
74+
alignwith = sizeof(TYPE_OF_WORD);
75+
else
76+
alignwith = sizeof(void*);
77+
78+
pad = alignwith - (sizeof(struct chunkHeader) % alignwith);
79+
80+
if (pad == alignwith)
7381
return 0;
7482
else
7583
return pad;
7684
}
7785

7886
static size_t getTrailerPad(size_t length) {
79-
size_t pad = sizeof(uintmax_t) - (length % sizeof(uintmax_t));
80-
if (pad == sizeof(uintmax_t))
87+
size_t alignwith, pad;
88+
89+
if (sizeof(TYPE_OF_WORD) > sizeof(void*))
90+
alignwith = sizeof(TYPE_OF_WORD);
91+
else
92+
alignwith = sizeof(void*);
93+
94+
pad = alignwith - (length % alignwith);
95+
96+
if (pad == alignwith)
8197
return 0;
8298
else
8399
return pad;

batman.h

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
#include <stdint.h>
3232
#include <stdio.h>
3333

34+
#define TYPE_OF_WORD uintmax_t /* you should choose something big, if you don't want to waste cpu */
35+
3436
#include "list-batman.h"
3537
#include "bitarray.h"
3638
#include "hash.h"

bitarray.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@
2121

2222

2323

24-
#define TYPE_OF_WORD unsigned long /* you should choose something big, if you don't want to waste cpu */
25-
#define WORD_BIT_SIZE ( sizeof(TYPE_OF_WORD) * 8 )
2624
#include "batman.h"
27-
25+
#define WORD_BIT_SIZE ( sizeof(TYPE_OF_WORD) * 8 )
2826

2927

3028
void bit_init( TYPE_OF_WORD *seq_bits );

0 commit comments

Comments
 (0)