small bitmap.c patch
andreas moroder
claudiamoroder at st-ulrich.suedtirol.net
Sat Sep 22 05:26:03 GMT 2001
Hello,
my patch does optimize a little ( very little ) bit bitmap.c
It is not a speed optimization ( it is also ) but a memory optimization.
Every malloc uses additional memory for his own purposes, so where we can
avoid allocating two blocks we should put them togheter.
Bye
Andreas
P.S. Patch against HEAD CVS from 21.9.2001 14.00 CEST
diff -r -u --exclude-from=exclude source/include/smb.h andreas/include/smb.h
--- source/include/smb.h Tue Sep 18 08:41:28 2001
+++ andreas/include/smb.h Sat Sep 22 13:25:16 2001
@@ -710,8 +710,8 @@
};
struct bitmap {
- uint32 *b;
int n;
+ uint32 b[1];
};
#define FLAG_BASIC 0x01 /* fundamental options */
diff -r -u --exclude-from=exclude source/lib/bitmap.c andreas/lib/bitmap.c
--- source/lib/bitmap.c Mon Sep 17 04:19:43 2001
+++ andreas/lib/bitmap.c Sat Sep 22 14:14:11 2001
@@ -33,19 +33,17 @@
struct bitmap *bitmap_allocate(int n)
{
struct bitmap *bm;
+ int size;
- bm = (struct bitmap *)malloc(sizeof(*bm));
+ size=sizeof(*bm)+sizeof(bm->b[0])*((n-1)/32);
+ bm = (struct bitmap *)malloc(size);
if (!bm) return NULL;
+
+ memset(bm, 0, size);
bm->n = n;
- bm->b = (uint32 *)malloc(sizeof(bm->b[0])*(n+31)/32);
- if (!bm->b) {
- SAFE_FREE(bm);
- return NULL;
- }
- memset(bm->b, 0, sizeof(bm->b[0])*(n+31)/32);
return bm;
}
@@ -56,10 +54,6 @@
void bitmap_free(struct bitmap *bm)
{
- if (!bm)
- return;
-
- SAFE_FREE(bm->b);
SAFE_FREE(bm);
}
More information about the samba-technical
mailing list