[layers] Stats on memory usage in the Stats screen. Tracks the number and total memory size of the pages (bitmaps) used by layers and their backups. Doesn't count housekeeping costs.
git-svn-id: svn://pulkomandy.tk/GrafX2/branches/layers@1074 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
parent
7690cd9e50
commit
2dcc1cf8bd
11
help.c
11
help.c
@ -45,6 +45,7 @@
|
||||
#include "input.h"
|
||||
#include "hotkeys.h"
|
||||
#include "errors.h"
|
||||
#include "pages.h"
|
||||
|
||||
// Recherche un raccourci clavier:
|
||||
word * Shortcut(word shortcut_number)
|
||||
@ -637,6 +638,16 @@ void Button_Stats(void)
|
||||
sprintf(buffer,"%u bytes",(unsigned int)freeRam);
|
||||
Print_in_window(114,51,buffer,STATS_DATA_COLOR,MC_Black);
|
||||
|
||||
// Used memory
|
||||
Print_in_window(10,59,"Used memory pages: ",STATS_TITLE_COLOR,MC_Black);
|
||||
if(Stats_pages_memory > (100LL*1024*1024*1024))
|
||||
sprintf(buffer,"%u (%u Gb)",Stats_pages_number, (unsigned int)(Stats_pages_memory/(1024*1024*1024)));
|
||||
else if(Stats_pages_memory > (100*1024*1024))
|
||||
sprintf(buffer,"%u (%u Mb)",Stats_pages_number, (unsigned int)(Stats_pages_memory/(1024*1024)));
|
||||
else
|
||||
sprintf(buffer,"%u (%u Kb)",Stats_pages_number, (unsigned int)(Stats_pages_memory/1024));
|
||||
Print_in_window(162,59,buffer,STATS_DATA_COLOR,MC_Black);
|
||||
|
||||
// Affichage de l'espace disque libre
|
||||
sprintf(buffer,"Free space on %c:",Main_current_directory[0]);
|
||||
Print_in_window(10,67,buffer,STATS_TITLE_COLOR,MC_Black);
|
||||
|
||||
24
pages.c
24
pages.c
@ -38,6 +38,11 @@
|
||||
/// Bitfield which records which layers are backed up in Page 0.
|
||||
static word Last_backed_up_layers=0;
|
||||
|
||||
/// Total number of unique bitmaps (layers, animation frames, backups)
|
||||
long Stats_pages_number=0;
|
||||
/// Total memory used by bitmaps (layers, animation frames, backups)
|
||||
long long Stats_pages_memory=0;
|
||||
|
||||
/// Allocate and initialize a new page.
|
||||
T_Page * New_page(byte nb_layers)
|
||||
{
|
||||
@ -79,22 +84,31 @@ byte * New_layer(long pixel_size)
|
||||
short * ptr = malloc(sizeof(short)+pixel_size);
|
||||
if (ptr==NULL)
|
||||
return NULL;
|
||||
|
||||
// Stats
|
||||
Stats_pages_number++;
|
||||
Stats_pages_memory+=pixel_size;
|
||||
|
||||
*ptr = 1;
|
||||
return (byte *)(ptr+1);
|
||||
}
|
||||
|
||||
/// Free a layer
|
||||
void Free_layer(byte * layer)
|
||||
void Free_layer(T_Page * page, byte layer)
|
||||
{
|
||||
short * ptr = (short *)(layer);
|
||||
if (layer==NULL)
|
||||
short * ptr;
|
||||
if (page->Image[layer]==NULL)
|
||||
return;
|
||||
|
||||
ptr = (short *)(page->Image[layer]);
|
||||
if (-- (*(ptr-1))) // Users--
|
||||
return;
|
||||
else
|
||||
free(ptr-1);
|
||||
|
||||
// Stats
|
||||
Stats_pages_number--;
|
||||
Stats_pages_memory-=page->Width * page->Height;
|
||||
}
|
||||
|
||||
/// Duplicate a layer (new reference)
|
||||
@ -321,7 +335,7 @@ void Clear_page(T_Page * page)
|
||||
int i;
|
||||
for (i=0; i<page->Nb_layers; i++)
|
||||
{
|
||||
Free_layer(page->Image[i]);
|
||||
Free_layer(page, i);
|
||||
page->Image[i]=NULL;
|
||||
}
|
||||
page->Width=0;
|
||||
@ -1019,7 +1033,7 @@ byte Delete_layer(T_List_of_pages *list, byte layer)
|
||||
// and so it will be cleared anyway.
|
||||
|
||||
// Smart freeing of the pixel data
|
||||
Free_layer(list->Pages->Image[layer]);
|
||||
Free_layer(list->Pages, layer);
|
||||
|
||||
list->Pages->Nb_layers--;
|
||||
// Move around the pointers. This part is going to be tricky when we
|
||||
|
||||
9
pages.h
9
pages.h
@ -90,4 +90,13 @@ void Update_depth_buffer(void);
|
||||
void Redraw_layered_image(void);
|
||||
void Redraw_current_layer(void);
|
||||
|
||||
///
|
||||
/// STATISTICS
|
||||
///
|
||||
|
||||
/// Total number of unique bitmaps (layers, animation frames, backups)
|
||||
extern long Stats_pages_number;
|
||||
/// Total memory used by bitmaps (layers, animation frames, backups)
|
||||
extern long long Stats_pages_memory;
|
||||
|
||||
#endif
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user