Browse Source

engine: netchan: fixed fragbufs very high memory usage

pull/2/head
SNMetamorph 2 years ago committed by Alibek Omarov
parent
commit
840283d6e5
  1. 14
      engine/common/net_chan.c
  2. 2
      engine/common/netchan.h

14
engine/common/net_chan.c

@ -414,6 +414,7 @@ void Netchan_ClearFragbufs( fragbuf_t **ppbuf ) @@ -414,6 +414,7 @@ void Netchan_ClearFragbufs( fragbuf_t **ppbuf )
while( buf )
{
n = buf->next;
Mem_Free( buf->frag_message_buf );
Mem_Free( buf );
buf = n;
}
@ -535,12 +536,13 @@ Netchan_AllocFragbuf @@ -535,12 +536,13 @@ Netchan_AllocFragbuf
==============================
*/
fragbuf_t *Netchan_AllocFragbuf( void )
fragbuf_t *Netchan_AllocFragbuf( int fragment_size )
{
fragbuf_t *buf;
buf = (fragbuf_t *)Mem_Calloc( net_mempool, sizeof( fragbuf_t ));
MSG_Init( &buf->frag_message, "Frag Message", buf->frag_message_buf, sizeof( buf->frag_message_buf ));
buf->frag_message_buf = (byte *)Mem_Calloc( net_mempool, fragment_size );
MSG_Init( &buf->frag_message, "Frag Message", buf->frag_message_buf, fragment_size );
return buf;
}
@ -736,7 +738,7 @@ static void Netchan_CreateFragments_( netchan_t *chan, sizebuf_t *msg ) @@ -736,7 +738,7 @@ static void Netchan_CreateFragments_( netchan_t *chan, sizebuf_t *msg )
bytes = Q_min( remaining, chunksize );
remaining -= bytes;
buf = Netchan_AllocFragbuf();
buf = Netchan_AllocFragbuf( bytes );
buf->bufferid = bufferid++;
// Copy in data
@ -803,7 +805,7 @@ fragbuf_t *Netchan_FindBufferById( fragbuf_t **pplist, int id, qboolean allocate @@ -803,7 +805,7 @@ fragbuf_t *Netchan_FindBufferById( fragbuf_t **pplist, int id, qboolean allocate
return NULL;
// create new entry
pnewbuf = Netchan_AllocFragbuf();
pnewbuf = Netchan_AllocFragbuf( NET_MAX_FRAGMENT );
pnewbuf->bufferid = id;
Netchan_AddBufferToList( pplist, pnewbuf );
@ -894,7 +896,7 @@ void Netchan_CreateFileFragmentsFromBuffer( netchan_t *chan, const char *filenam @@ -894,7 +896,7 @@ void Netchan_CreateFileFragmentsFromBuffer( netchan_t *chan, const char *filenam
{
send = Q_min( remaining, chunksize );
buf = Netchan_AllocFragbuf();
buf = Netchan_AllocFragbuf( send );
buf->bufferid = bufferid++;
// copy in data
@ -1013,7 +1015,7 @@ int Netchan_CreateFileFragments( netchan_t *chan, const char *filename ) @@ -1013,7 +1015,7 @@ int Netchan_CreateFileFragments( netchan_t *chan, const char *filename )
{
send = Q_min( remaining, chunksize );
buf = Netchan_AllocFragbuf();
buf = Netchan_AllocFragbuf( send );
buf->bufferid = bufferid++;
// copy in data

2
engine/common/netchan.h

@ -185,7 +185,7 @@ typedef struct fragbuf_s @@ -185,7 +185,7 @@ typedef struct fragbuf_s
struct fragbuf_s *next; // next buffer in chain
int bufferid; // id of this buffer
sizebuf_t frag_message; // message buffer where raw data is stored
byte frag_message_buf[NET_MAX_FRAGMENT]; // the actual data sits here
byte *frag_message_buf; // the actual data sits here
qboolean isfile; // is this a file buffer?
qboolean isbuffer; // is this file buffer from memory ( custom decal, etc. ).
qboolean iscompressed; // is compressed file, we should using filename.ztmp

Loading…
Cancel
Save