From 3ba802e99524797571e69ba57b6a30a12b031b72 Mon Sep 17 00:00:00 2001 From: rubidium Date: Mon, 23 Feb 2009 17:54:02 +0000 Subject: (svn r15556) -Change: don't temporary malloc+free when encoding sprites, just reuse the same piece of allocated memory for each encoding. --- src/blitter/8bpp_optimized.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/blitter') diff --git a/src/blitter/8bpp_optimized.cpp b/src/blitter/8bpp_optimized.cpp index 350715dc6..62fae35c8 100644 --- a/src/blitter/8bpp_optimized.cpp +++ b/src/blitter/8bpp_optimized.cpp @@ -113,7 +113,12 @@ Sprite *Blitter_8bppOptimized::Encode(SpriteLoader::Sprite *sprite, Blitter::All /* We have no idea how much memory we really need, so just guess something */ memory *= 5; - SpriteData *temp_dst = (SpriteData *)MallocT(memory); + + /* Don't allocate memory each time, but just keep some + * memory around as this function is called quite often + * and the memory usage is quite low. */ + static ReusableBuffer temp_buffer; + SpriteData *temp_dst = (SpriteData *)temp_buffer.Allocate(memory); byte *dst = temp_dst->data; /* Make the sprites per zoom-level */ @@ -195,7 +200,6 @@ Sprite *Blitter_8bppOptimized::Encode(SpriteLoader::Sprite *sprite, Blitter::All dest_sprite->x_offs = sprite->x_offs; dest_sprite->y_offs = sprite->y_offs; memcpy(dest_sprite->data, temp_dst, size); - free(temp_dst); return dest_sprite; } -- cgit v1.2.3-70-g09d2