-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move CLI history into the heap #83
Conversation
first step in moving history to heap
uses less memory :D
when going up/down if the current buffer is smaller than the history entry we need to truncate, otherwise we will overflow and corrupt our heap
@@ -43,7 +43,7 @@ extern BYTE scrcols; | |||
|
|||
// Storage for the command history | |||
// | |||
static char cmd_history[cmd_historyDepth][cmd_historyWidth + 1]; | |||
static char * cmd_history[cmd_historyDepth]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the approach taken here is to use an array of pointers to strings for history entries
I did consider using a linked list, where we'd just store a pointer to the first history entry. this would remove the need to shuffle history entries when we've reached our size limit. for now that approach hasn't been taken
strncpy(cmd_history[history_size++], buffer, cmd_historyWidth); // Save in the history | ||
history_no = history_size; | ||
} | ||
editHistoryPush(buffer); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this switch got refactored to use functions for each history action so as to allow those functions to more easily be refactored to use a different way to store history items
int i; | ||
umm_free(cmd_history[0]); | ||
for (i = 1; i < history_size; i++) { | ||
cmd_history[i - 1] = cmd_history[i]; | ||
} | ||
history_size--; | ||
} | ||
cmd_history[history_size++] = newEntry; | ||
history_no = history_size; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we were using a linked list approach for the history this would be simplified to replace the current "head" of the history list with the new entry (which would point to the previous head), and optionally to trim the list
future ideas/plans for exposing history via system variables could be complicated by that tho, so for now we're using a simple array. when system variables are added and if/when the history gets exposed this idea may be revisited
Changes how CLI history is recorded, moving it from a static fixed length array of chars to storing pointers to variable length strings in the heap
Duplicate history items are no longer pushed, altho this check is only against the most recent history entry
This gives us a chunk more heap space