dankamongmen / notcurses

blingful character graphics/TUI library. definitely not curses.
https://nick-black.com/dankwiki/index.php/Notcurses
Other
3.48k stars 112 forks source link

regarding ncstats initialization and deallocation #2665

Open joseluis opened 2 years ago

joseluis commented 2 years ago

Working on the ncstats bindings I found something interesting:

  1. Without banners, If I don't call notcurses_stats after allocating a new ncstats object, the preallocated number of renders is absurdly high.
  2. With banners, If I don't call notcurses_stats after allocating a new ncstats object, the preallocated number of renders is 0. I guess that's expected.

I also want to confirm whether I should use free to deallocate the ncstats objects before the end of the program. In that case maybe they ought to have have a destroy function?

I made a small C program:

#include <notcurses/notcurses.h>
int main(void){
    // ISSUE-1: uncomment this:
    struct notcurses_options nopts = { .flags = NCOPTION_SUPPRESS_BANNERS | NCOPTION_CLI_MODE };

    // ISSUE-2: uncomment this:
    // struct notcurses_options nopts = { .flags = NCOPTION_CLI_MODE };

    struct notcurses* nc = notcurses_core_init(&nopts, NULL);
    if(nc == NULL){ return EXIT_FAILURE; }

    // 1st render, before allocation
    notcurses_render(nc);
    struct ncstats* stats = notcurses_stats_alloc(nc);

    // ISSUE-1 & ISSUE-2: leave commented out this:
    notcurses_stats(nc, stats);

    fprintf(stderr, "\nrenders:%lld\n", stats->renders);

    // 2nd render
    notcurses_render(nc);
    notcurses_stats(nc, stats);
    fprintf(stderr, "renders:%lld\n", stats->renders);

    // resetting
    notcurses_stats_reset(nc, stats);
    notcurses_stats(nc, stats);
    fprintf(stderr, "renders:%lld\n\n", stats->renders);

    if (notcurses_stop(nc)) { return EXIT_FAILURE; }
    return EXIT_SUCCESS;
}

results


# A
renders:140075559345600
renders:2
renders:0

# B
renders:0
renders:2
renders:0

# calling notcurses_stats after allocation 
renders:1
renders:2
renders:0