X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Frts%2FArena.c;h=2c478a70b7717a7d4c991fa51fd29a600657defc;hb=870b2298d73c55a50d17bbe160ea51354ace7a19;hp=f719400c9e4a0ddf814971d425c1dccbe8d8c238;hpb=bda943136e7dee3ad36e368fd81014850b5d6db9;p=ghc-hetmet.git diff --git a/ghc/rts/Arena.c b/ghc/rts/Arena.c index f719400..2c478a7 100644 --- a/ghc/rts/Arena.c +++ b/ghc/rts/Arena.c @@ -1,5 +1,4 @@ /* ----------------------------------------------------------------------------- - $Id: Arena.c,v 1.1 2001/10/18 14:41:01 simonmar Exp $ (c) The University of Glasgow 2001 Arena allocation. Arenas provide fast memory allocation at the @@ -19,6 +18,7 @@ which most allocations are small. -------------------------------------------------------------------------- */ +#include #include "Rts.h" #include "RtsUtils.h" #include "BlockAlloc.h" @@ -51,6 +51,13 @@ newArena( void ) return arena; } +// The minimum alignment of an allocated block. +#define MIN_ALIGN 8 + +/* 'n' is assumed to be a power of 2 */ +#define ROUNDUP(x,n) (((x)+((n)-1))&(~((n)-1))) +#define B_TO_W(x) ((x) / sizeof(W_)) + // Allocate some memory in an arena void * arenaAlloc( Arena *arena, size_t size ) @@ -60,8 +67,11 @@ arenaAlloc( Arena *arena, size_t size ) nat req_blocks; bdescr *bd; - // round up to word size... - size_w = (size + sizeof(W_) - 1) / sizeof(W_); + // round up to nearest alignment chunk. + size = ROUNDUP(size,MIN_ALIGN); + + // size of allocated block in words. + size_w = B_TO_W(size); if ( arena->free + size_w < arena->lim ) { // enough room in the current block... @@ -70,7 +80,7 @@ arenaAlloc( Arena *arena, size_t size ) return p; } else { // allocate a fresh block... - req_blocks = (lnat)BLOCK_ROUND_UP(size_w*sizeof(W_)) / BLOCK_SIZE; + req_blocks = (lnat)BLOCK_ROUND_UP(size) / BLOCK_SIZE; bd = allocGroup(req_blocks); arena_blocks += req_blocks; @@ -98,7 +108,7 @@ arenaFree( Arena *arena ) ASSERT(arena_blocks >= 0); freeGroup(bd); } - free(arena); + stgFree(arena); } unsigned long