add mem_stream_make_sized, meant to make saving games more efficient

This commit is contained in:
Eric House 2012-09-11 19:06:27 -07:00
parent 75474e1891
commit 5c683f173a
2 changed files with 19 additions and 3 deletions

View file

@ -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 )
{

View file

@ -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
}