htop icon indicating copy to clipboard operation
htop copied to clipboard

Allocate GraphData buffer dynamically

Open zevweiss opened this issue 2 years ago • 5 comments

I occasionally run htop in a full-screen terminal on a wide monitor, which had been producing a clunkily truncated CPU graph in the header section:

htop

Bumping METER_GRAPHDATA_SIZE up to 1024 resolves the problem.

zevweiss avatar May 22 '22 03:05 zevweiss

I'm not sure of it's a good idea to expand METER_GRAPHDATA_SIZE unconditionally in all htop builds.

Explorer09 avatar May 23 '22 07:05 Explorer09

The better solution would dynamically allocate that memory and resize if necessary.

BenBE avatar May 23 '22 08:05 BenBE

I'm not sure of it's a good idea to expand METER_GRAPHDATA_SIZE unconditionally in all htop builds.

Just due to the added memory consumption, or for some other reason? It'll increase the values array in the GraphData struct from 2K to 8K, though it's not like there should be lots of instances of that running around (one per active graph-mode meter), so I'd expect the difference to still be in "pocket change" territory for the kinds of systems htop is typically used on.

The better solution would dynamically allocate that memory and resize if necessary.

Ideally, sure, but that would also have to factor in reallocating on SIGWINCH and such; I'll take a glance at what implementing that would involve, but if it ends up taking longer than I have to invest in it in at the moment I'd still be in favor of a simple one-line patch to improve on the status quo...

zevweiss avatar May 23 '22 08:05 zevweiss

...okay, the dynamic-allocation approach turned out to be simpler to implement than expected, so I guess we might as well go with that.

zevweiss avatar May 23 '22 09:05 zevweiss

@zevweiss I think I'll incorporate your dynamic allocation change to my "colored graph" proposal (#714 ). With the colored graph feature, the GraphData buffer would need to be dynamically allocated anyway. Let's avoid duplicated efforts.

Explorer09 avatar May 23 '22 10:05 Explorer09