1
0
mirror of https://github.com/rfivet/uemacs.git synced 2024-11-17 18:16:22 -05:00

Allocate screen memory on change of window size instead of one static huge allocation.

This commit is contained in:
Renaud 2021-08-24 16:00:32 +08:00
parent e2f7cc0566
commit 699dac8b27

View File

@ -28,7 +28,6 @@
#include "termio.h" #include "termio.h"
#include "terminal.h" #include "terminal.h"
#include "version.h" #include "version.h"
//#include "wrapper.h"
#include "utf8.h" #include "utf8.h"
#include "window.h" #include "window.h"
@ -122,6 +121,32 @@ static void *xmalloc( size_t size) {
compile time. The original window has "WFCHG" set, so that it will get compile time. The original window has "WFCHG" set, so that it will get
completely redrawn on the first call to "update". completely redrawn on the first call to "update".
*/ */
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( maxrow * sizeof( video_p )) ;
#endif
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 + maxcol * sizeof( unicode_t)) ;
vp->v_flag = 0 ;
pscreen[ i] = vp ;
#endif
}
}
void vtinit( void) { void vtinit( void) {
#ifdef SIGWINCH #ifdef SIGWINCH
signal( SIGWINCH, sizesignal) ; signal( SIGWINCH, sizesignal) ;
@ -131,32 +156,14 @@ void vtinit( void) {
TTopen() ; /* open the screen */ TTopen() ; /* open the screen */
TTkopen() ; /* open the keyboard */ TTkopen() ; /* open the keyboard */
TTrev( FALSE) ; TTrev( FALSE) ;
vscreen = xmalloc( term.t_maxrow * sizeof( video_p )) ; vtalloc( term.t_mrow, term.t_mcol) ;
#if MEMMAP == 0 || SCROLLCODE
pscreen = xmalloc( term.t_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)) ;
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->v_flag = 0 ;
pscreen[ i] = vp ;
#endif
}
} }
#if CLEAN
/* free up all the dynamically allocated video structures */ /* free up all the dynamically video structures allocated by vtalloc */
void vtfree( void) { void vtfree( void) {
/* as xmalloc bypass the malloc macro, we need bypass the free macro too */ /* 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]) ; (free)( vscreen[ i]) ;
#if MEMMAP == 0 || SCROLLCODE #if MEMMAP == 0 || SCROLLCODE
(free)( pscreen[ i]) ; (free)( pscreen[ i]) ;
@ -168,7 +175,7 @@ void vtfree( void) {
(free)( pscreen) ; (free)( pscreen) ;
#endif #endif
} }
#endif
/* Clean up the virtual terminal system, in anticipation for a return to /* Clean up the virtual terminal system, in anticipation for a return to
@ -1455,6 +1462,8 @@ static int newscreensize( int h, int w) {
} }
chg_width = chg_height = 0 ; chg_width = chg_height = 0 ;
vtfree() ;
vtalloc( h, w) ;
if( h <= term.t_mrow) if( h <= term.t_mrow)
newsize( TRUE, h) ; newsize( TRUE, h) ;