summaryrefslogtreecommitdiff
path: root/perl.h
diff options
context:
space:
mode:
authorWolfram Humann <w.c.humann@arcor.de>2010-08-13 17:20:26 -0700
committerJan Dubois <jand@activestate.com>2010-08-13 17:20:26 -0700
commitf12005599f648e675af22dfef1047191e260bc48 (patch)
tree1934c0fbfa617ea7780eac79a73f1bd20d81c8ed /perl.h
parent24e93d7838b346d2ed632075f3d824a325170616 (diff)
downloadperl-f12005599f648e675af22dfef1047191e260bc48.tar.gz
make string-append on win32 100 times faster
When a string grows (e.g. gets appended to), perl calls sv_grow. When sv_grow decides that the memory currently allocated to the string is insufficient, it calls saferealloc. Depending on whether or not perl was compiled with 'usemymalloc' this calls realloc in either perls internal version or on the operating system. Perl requests from realloc just the amount of memory required for the current operation. With 'usemymalloc' this is not a problem because it rounds up memory allocation to a certain geometric progression anyway. When the operating system's realloc is called, this may or may not lead to desaster, depending on how it's implemented. On win32 it does lead to desaster: when I loop 1000 times and each time append 1000 chars to an initial string size of 10 million, the memory grows from 10.000e6 to 10.001e6 to 10.002e6 and so on 1000 times till it ends at 11.000e6.
Diffstat (limited to 'perl.h')
-rw-r--r--perl.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/perl.h b/perl.h
index 59df0aaba7..74fb62ecb7 100644
--- a/perl.h
+++ b/perl.h
@@ -979,6 +979,14 @@ EXTERN_C int usleep(unsigned int);
#define PERL_STRLEN_ROUNDUP_QUANTUM Size_t_size
#endif
+/* sv_grow() will expand strings by at least a certain percentage of
+ the previously *used* length to avoid excessive calls to realloc().
+ The default is 25% of the current length.
+*/
+#ifndef PERL_STRLEN_EXPAND_SHIFT
+# define PERL_STRLEN_EXPAND_SHIFT 2
+#endif
+
#if defined(STANDARD_C) && defined(I_STDDEF)
# include <stddef.h>
# define STRUCT_OFFSET(s,m) offsetof(s,m)