Skip to content
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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Configurable UTSTRING_INITIAL_SIZE #146

wants to merge 4 commits into from

Conversation

silvioprog
Copy link

No description provided.

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
Copy link
Collaborator

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 -Define, 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.

Copy link
Author

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! 😅

Copy link
Author

@silvioprog silvioprog Feb 16, 2018

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(); \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merged as 29fc26a — thanks!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're welcome dude! 👍

@Quuxplusone Quuxplusone changed the title Small fixes Configurable UTSTRING_INITIAL_SIZE Apr 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants