From 5c683f173ab6a54df9b05a5f6f01fcc350fd6092 Mon Sep 17 00:00:00 2001 From: Eric House Date: Tue, 11 Sep 2012 19:06:27 -0700 Subject: [PATCH] add mem_stream_make_sized, meant to make saving games more efficient --- xwords4/common/memstream.c | 17 ++++++++++++++--- xwords4/common/memstream.h | 5 +++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/xwords4/common/memstream.c b/xwords4/common/memstream.c index 095e52845..f3c627491 100644 --- a/xwords4/common/memstream.c +++ b/xwords4/common/memstream.c @@ -70,10 +70,8 @@ mem_stream_make( MPFORMAL VTableMgr* vtmgr, void* closure, XP_PlayerAddr channelNo, MemStreamCloseCallback onClose ) { StreamCtxVTable* vtable; - MemStreamCtxt* result = (MemStreamCtxt*)XP_MALLOC( mpool, + MemStreamCtxt* result = (MemStreamCtxt*)XP_CALLOC( mpool, sizeof(*result) ); - XP_MEMSET( result, 0, sizeof(*result) ); - MPASSIGN(result->mpool, mpool); vtable = (StreamCtxVTable*)vtmgr_getVTable( vtmgr, VTABLE_MEM_STREAM ); @@ -92,6 +90,19 @@ mem_stream_make( MPFORMAL VTableMgr* vtmgr, void* closure, return (XWStreamCtxt*)result; } /* make_mem_stream */ +XWStreamCtxt* +mem_stream_make_sized( MPFORMAL VTableMgr* vtmgr, XP_U16 startSize, + void* closure, XP_PlayerAddr channelNo, + MemStreamCloseCallback onClose ) +{ + MemStreamCtxt* result = + (MemStreamCtxt*)mem_stream_make( MPPARM(mpool) vtmgr, closure, + channelNo, onClose ); + result->buf = (XP_U8*)XP_MALLOC( mpool, startSize ); + result->nBytesAllocated = startSize; + return (XWStreamCtxt*)result; +} + static void mem_stream_getBytes( XWStreamCtxt* p_sctx, void* where, XP_U16 count ) { diff --git a/xwords4/common/memstream.h b/xwords4/common/memstream.h index ea9c1245a..5091088f2 100644 --- a/xwords4/common/memstream.h +++ b/xwords4/common/memstream.h @@ -38,6 +38,11 @@ XWStreamCtxt* mem_stream_make( MPFORMAL VTableMgr* vtmgr, subclass */ MemStreamCloseCallback onCloseWritten ); +XWStreamCtxt* mem_stream_make_sized( MPFORMAL VTableMgr* vtmgr, + XP_U16 initialSize, + void* closure, XP_PlayerAddr addr, + MemStreamCloseCallback onCloseWritten ); + #ifdef CPLUS }