-
Notifications
You must be signed in to change notification settings - Fork 923
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
Configurable UTSTRING_INITIAL_SIZE #146
base: master
Are you sure you want to change the base?
Conversation
src/utstring.h
Outdated
@@ -43,6 +43,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
#define oom() exit(-1) | |||
#endif | |||
|
|||
#ifndef UTSTRING_INITIAL_SIZE | |||
#define UTSTRING_INITIAL_SIZE 0x64 | |||
#endif |
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.
(A) If somebody has a strong use-case for tweaking this specific parameter (UTSTRING_INITIAL_SIZE
), then I might be swayed; but a priori, I'd rather see this particular diff come as part of a larger, comprehensive thinking-out of utstring's allocation machinery. Like, maybe it should be using a primitive such as utstring_realloc
that the user is allowed to -D
efine, and maybe we need to think about what realloc-of-size-zero means, and so on.
(B) Writing 0x64
when you mean 100
is just as confusing as writing 0100
when you mean 64
. I don't know why you'd do that.
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.
(A) 1. On embedded systems (e.g: an AVR/PIC with just 512 of RAM), the programmer could choose a value smaller than 100; On common fast systems, it can be increased (1 kB, 8 kB) via building system.
(B) Oops, sorry. It was just a habit from microcontroller coding! 😅
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.
(B) additional info: It uses the same concept: https://github.com/troydhanson/libut/blob/master/src/utvector.c#L29 . (however INITIAL_SIZE
should be prefixed to UTVECTOR_INITIAL_SIZE
avoiding to conflict on user macros)
s = (UT_string*)malloc(sizeof(UT_string)); \ | ||
if (!s) oom(); \ | ||
(s) = (UT_string*)malloc(sizeof(UT_string)); \ | ||
if (!(s)) oom(); \ |
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.
Merged as 29fc26a — thanks!
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.
You're welcome dude! 👍
No description provided.