From 4443bc775442d568357f72d96e2fbdae2ea58c3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Fri, 17 Jun 2016 05:11:29 +0200 Subject: make_preload: Save some memory by making preloaded code 'const' Mark the preloaded code 'const' to allow the compiler to put it into the 'text' segment instead of into the 'data' segment. Since the 'text' segment is shared among all instances of the Erlang virtual machine, this change could potentially reduce memory consumption (slightly). Before the change: $ size bin/x86_64-unknown-linux-gnu/beam.smp text data bss dec hex filename 2920246 352273 158472 3430991 345a4f bin/x86_64-unknown-linux-gnu/beam.smp After the change: $ size bin/x86_64-unknown-linux-gnu/beam.smp text data bss dec hex filename 3081046 191473 158472 3430991 345a4f bin/x86_64-unknown-linux-gnu/beam.smp Roughly speaking, this change cuts the size of the data segment in half. --- erts/emulator/utils/make_preload | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'erts') diff --git a/erts/emulator/utils/make_preload b/erts/emulator/utils/make_preload index f489bc2a39..8b629d9517 100755 --- a/erts/emulator/utils/make_preload +++ b/erts/emulator/utils/make_preload @@ -94,8 +94,8 @@ foreach $file (@ARGV) { close(FILE); push(@modules, " {\"$module\", " . length($_) . ", preloaded_$module},\n"); - print "unsigned preloaded_size_$module = ", length($_), ";\n"; - print "unsigned char preloaded_$module", "[] = {\n"; + print "const unsigned preloaded_size_$module = ", length($_), ";\n"; + print "const unsigned char preloaded_$module", "[] = {\n"; for ($i = 0; $i < length($_); $i++) { if ($i % 8 == 0 && $comment ne '') { $comment =~ s@/\*@..@g; # Comment start -- avoid warning. @@ -125,10 +125,10 @@ if ($gen_rc) { print @modules; print "END\n"; } elsif ($gen_old) { - print "struct {\n"; + print "const struct {\n"; print " char* name;\n"; print " int size;\n"; - print " unsigned char* code;\n"; + print " const unsigned char* code;\n"; print "} pre_loaded[] = {\n"; foreach (@modules) { print; -- cgit v1.2.3