LemonBoy / bar

A featherweight, lemon-scented, bar based on xcb
MIT License
1.63k stars 194 forks source link

Added dynamic input allocation and cleaned up some trailing whitespace. #54

Closed brycereitano closed 10 years ago

brycereitano commented 10 years ago

Simple change to allow input of an unknown line length. The input will start at 1024 characters, if the buffer is not large enough it will expand by 2x. Example: 1024->2048->4096->etc..

kevinvdburgt commented 10 years ago

Isnt this using much more ram with realloc ?

brycereitano commented 10 years ago

As far as I understand, feel free to correct me if I'm wrong. As long as I'm freeing up the memory when I'm done with it. It will only use the memory required. For example when it expands to 2048 it should only be using 2024*sizeof(char).

However, I think you do have a point. I am using more memory storing and applying it to the buffer. At most, I should only be using double the buffer size.

LemonBoy commented 10 years ago

Continuous malloc/realloc is definitely not good, also there's the FIONREAD ioctl to avoid reading one char a time