Introduction
Introduction Statistics Contact Development Disclaimer Help
improve memory usage and allocation - webdump - HTML to plain-text converter fo…
git clone git://git.codemadness.org/webdump
Log
Files
Refs
README
LICENSE
---
commit 5cde25b5150bd0375e9b5800bf3855765830c588
parent 72b23084b7c64c298c6b90ae6ad9f53f497cec57
Author: Hiltjo Posthuma <[email protected]>
Date: Sat, 6 Jul 2024 13:05:54 +0200
improve memory usage and allocation
Do not realloc when it is not needed (even when it is the same size).
Decrease the greedy allocation increment size for nested nodes also.
Tested for example using valgrind and "add Beej's Guide to Network Programming"…
https://git.codemadness.org/webdump_tests/commit/837749abc02f28e1584e5f2cf2b274…
The buffering for link references (-l option) used way too much memory.
Diffstat:
M webdump.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
---
diff --git a/webdump.c b/webdump.c
@@ -1420,15 +1420,17 @@ addlinkref(const char *url, const char *_type, enum Tag…
if (!ishidden) {
linknr = ++nvisrefs;
- if (nvisrefs >= ncapvisrefs)
+ if (nvisrefs >= ncapvisrefs) {
ncapvisrefs += 256; /* greedy alloc */
- visrefs = erealloc(visrefs, sizeof(*visrefs) * ncapvisrefs);
+ visrefs = erealloc(visrefs, sizeof(*visrefs) * ncapvis…
+ }
visrefs[linknr - 1] = link; /* add pointer to list */
} else {
linknr = ++nhiddenrefs;
- if (nhiddenrefs >= ncaphiddenrefs)
+ if (nhiddenrefs >= ncaphiddenrefs) {
ncaphiddenrefs += 256; /* greedy alloc */
- hiddenrefs = erealloc(hiddenrefs, sizeof(*hiddenrefs) * ncaphi…
+ hiddenrefs = erealloc(hiddenrefs, sizeof(*hiddenrefs) …
+ }
hiddenrefs[linknr - 1] = link; /* add pointer to list */
}
@@ -1534,7 +1536,7 @@ printlinkrefs(void)
}
/* size to grow node capacity (greedy) */
-#define NODE_CAP_INC 256
+#define NODE_CAP_INC 16
/* increase node depth, allocate space for nodes if needed */
static void
You are viewing proxied material from codemadness.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.