small bitmap.c patch

Simo Sorce idra at samba.org
Sat Sep 22 12:44:02 GMT 2001


On Sat, Sep 22, 2001 at 12:12:14PM -0700, Jeremy Allison wrote:
> On Sat, Sep 22, 2001 at 02:30:58PM +0200, andreas moroder wrote:
> > 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.
> 
> Actually, where speed and memory optimisation is not critical there are good reasons 
> for keeping the two separate. This is to allow automated tools such as insure++
> and purify to catch programming errors that cause overflow in one memory block
> to another.
> 
> Abutting memory areas like that makes it impossible for these tools to
> catch such an error. This is wht the talloc implementation currently
> does the same thing.
> 
> Jeremy.
> 

Well, I think this is not the case, but anyways the patch proposed,
is not very good.
It assumes the compiler will use the structure as it is declared,
but optimization can change this, it can reorder datafor speed or
memory optimization.
Here it is a patch that should issue this problem and also use only
one malloc.
I've not yet committed it to the branch, if jeremy or andrew are ok
with this kind of patch I will commit it.

Simo.
-- 
Simo Sorce       idra at samba.org
-------------------------------
Samba Team http://www.samba.org
-------------- next part --------------
37c37
< 	bm = (struct bitmap *)malloc(sizeof(*bm));
---
> 	bm = (struct bitmap *)malloc(sizeof(struct bitmap)+sizeof(uint32)*(n+31)/32);
42,48c42,43
< 	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);
---
> 	bm->b = (uint32 *)(bm + sizeof(struct bitmap));
> 	memset(bm->b, 0, sizeof(uint32)*(n+31)/32);
59,62c54,55
< 	if (!bm)
< 		return;
< 
< 	SAFE_FREE(bm->b);
---
> 	if (!bm) return;
> 	


More information about the samba-technical mailing list