summaryrefslogtreecommitdiff
path: root/src/blitter
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-02-23 17:54:02 +0000
committerrubidium <rubidium@openttd.org>2009-02-23 17:54:02 +0000
commit3ba802e99524797571e69ba57b6a30a12b031b72 (patch)
tree52608fad0b8c58f9fc141f8ff4e5d203be54f7fc /src/blitter
parent0c1b8ea602de72a96573b7e3301589e8e3249ca1 (diff)
downloadopenttd-3ba802e99524797571e69ba57b6a30a12b031b72.tar.xz
(svn r15556) -Change: don't temporary malloc+free when encoding sprites, just reuse the same piece of allocated memory for each encoding.
Diffstat (limited to 'src/blitter')
-rw-r--r--src/blitter/8bpp_optimized.cpp8
1 files changed, 6 insertions, 2 deletions
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<byte>(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<byte> 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;
}