Skip to content

Commit

Permalink
Allocate screen memory on change of window size instead of one static…
Browse files Browse the repository at this point in the history
… huge allocation.
  • Loading branch information
rfivet committed Aug 24, 2021
1 parent e2f7cc0 commit 699dac8
Showing 1 changed file with 27 additions and 18 deletions.
45 changes: 27 additions & 18 deletions display.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include "termio.h"
#include "terminal.h"
#include "version.h"
//#include "wrapper.h"
#include "utf8.h"
#include "window.h"

Expand Down Expand Up @@ -122,41 +121,49 @@ static void *xmalloc( size_t size) {
compile time. The original window has "WFCHG" set, so that it will get
completely redrawn on the first call to "update".
*/
void vtinit( void) {
#ifdef SIGWINCH
signal( SIGWINCH, sizesignal) ;
#endif

setlocale( LC_CTYPE, "") ; /* expects $LANG like en_GB.UTF-8 */
TTopen() ; /* open the screen */
TTkopen() ; /* open the keyboard */
TTrev( FALSE) ;
vscreen = xmalloc( term.t_maxrow * sizeof( video_p )) ;
static int lastmrow ; /* remember mrow for later free */

static void vtalloc( int maxrow, int maxcol) {
lastmrow = maxrow ; /* remember mrow for later free */
vscreen = xmalloc( maxrow * sizeof( video_p )) ;

#if MEMMAP == 0 || SCROLLCODE
pscreen = xmalloc( term.t_maxrow * sizeof( video_p )) ;
pscreen = xmalloc( maxrow * sizeof( video_p )) ;
#endif
for( int i = 0 ; i < term.t_maxrow ; ++i) {
video_p vp = xmalloc( sizeof *vp + term.t_maxcol * sizeof( unicode_t)) ;
for( int i = 0 ; i < maxrow ; ++i) {
video_p vp = xmalloc( sizeof *vp + maxcol * sizeof( unicode_t)) ;
vp->v_flag = 0 ;
#if COLOR
vp->v_rfcolor = 7 ;
vp->v_rbcolor = 0 ;
#endif
vscreen[ i] = vp ;
#if MEMMAP == 0 || SCROLLCODE
vp = xmalloc( sizeof *vp + term.t_maxcol * sizeof( unicode_t)) ;
vp = xmalloc( sizeof *vp + maxcol * sizeof( unicode_t)) ;
vp->v_flag = 0 ;
pscreen[ i] = vp ;
#endif
}
}

#if CLEAN
/* free up all the dynamically allocated video structures */
void vtinit( void) {
#ifdef SIGWINCH
signal( SIGWINCH, sizesignal) ;
#endif

setlocale( LC_CTYPE, "") ; /* expects $LANG like en_GB.UTF-8 */
TTopen() ; /* open the screen */
TTkopen() ; /* open the keyboard */
TTrev( FALSE) ;
vtalloc( term.t_mrow, term.t_mcol) ;
}


/* free up all the dynamically video structures allocated by vtalloc */
void vtfree( void) {
/* as xmalloc bypass the malloc macro, we need bypass the free macro too */
for( int i = 0 ; i < term.t_maxrow ; ++i ) {
for( int i = 0 ; i < lastmrow ; ++i ) {
(free)( vscreen[ i]) ;
#if MEMMAP == 0 || SCROLLCODE
(free)( pscreen[ i]) ;
Expand All @@ -168,7 +175,7 @@ void vtfree( void) {
(free)( pscreen) ;
#endif
}
#endif



/* Clean up the virtual terminal system, in anticipation for a return to
Expand Down Expand Up @@ -1455,6 +1462,8 @@ static int newscreensize( int h, int w) {
}

chg_width = chg_height = 0 ;
vtfree() ;
vtalloc( h, w) ;
if( h <= term.t_mrow)
newsize( TRUE, h) ;

Expand Down

0 comments on commit 699dac8

Please sign in to comment.