#Heap usage of empty main program

54 messages · Page 1 of 1 (latest)

sinful silo
#

I'm wondering why this program tested with valgrind requires 72,704 bytes allocated on the heap. Am I understanding wrong the valgrind message or there is actually something going on?

int main() { return 0; }
g++ --version
long totemBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For more information use !howto ask.

ionic dust
#

@sinful silo
how did you create the executable ./main

sinful silo
#

Right
g++ -o main main.cpp

ionic dust
#

try building with

#
g++ -O0 -g main.cpp -o main
sinful silo
#

already done

ionic dust
sinful silo
#

I mean that even by doing it, the amount of bytes allocated is the same

ionic dust
#
valgrind -s ./main
#

wait a minute

sinful silo
#

Why there should be a leak in that program?

ionic dust
sinful silo
ionic dust
#

now I see there are no leaks

sinful silo
#

So back to the question, do you know from where all those bytes come from?

ionic dust
sinful silo
#

yep

ionic dust
#

hmmmm I dont get any bytes allocated

ionic dust
sinful silo
#

You can find them in the screenshot

light axle
#

there's no real issue. it's just the runtime allocating memory. if you think it takes too much memory, you can compile your code into an assembly, modify the assembly, and compile from there.

glass bluff
#

unless you're doing anything else

#

Can I recommend address sanitizer over valgrind

sinful silo
ionic dust
sinful silo
glass bluff
#

You're using the standard library even if you don't #include anything

#

But that's just a guess

#

You can strace your program and see how it's getting pages from the os

sinful silo
ionic dust
#

with strace

sinful silo
#

ok mine is way way bigger

ionic dust
#

somewhere

#

kinda cringe, not gonna lie

sinful silo
#

w8, not actually that bigger, I missed a parameter and that resulted in a good 2 screen of text
now this is what I got

mmap(NULL, 181667, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f8c11314000
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f8c11312000
mmap(NULL, 2250816, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f8c110ec000
mmap(0x7f8c11185000, 1085440, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x99000) = 0x7f8c11185000
mmap(0x7f8c1128e000, 466944, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1a2000) = 0x7f8c1128e000
mmap(0x7f8c11301000, 57344, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x214000) = 0x7f8c11301000
mmap(0x7f8c1130f000, 10304, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f8c1130f000
mmap(NULL, 946752, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f8c11004000
mmap(0x7f8c11014000, 499712, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x10000) = 0x7f8c11014000
mmap(0x7f8c1108e000, 376832, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x8a000) = 0x7f8c1108e000
mmap(0x7f8c110ea000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0xe5000) = 0x7f8c110ea000
mmap(NULL, 107240, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f8c10fe9000
mmap(0x7f8c10fec000, 73728, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x3000) = 0x7f8c10fec000
mmap(0x7f8c10ffe000, 12288, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x15000) = 0x7f8c10ffe000
#
mmap(0x7f8c11002000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x18000) = 0x7f8c11002000
mmap(NULL, 2136752, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f8c10ddf000
mmap(0x7f8c10e0b000, 1531904, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x2c000) = 0x7f8c10e0b000
mmap(0x7f8c10f81000, 344064, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1a2000) = 0x7f8c10f81000
mmap(0x7f8c10fd6000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1f6000) = 0x7f8c10fd6000
mmap(0x7f8c10fdc000, 51888, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f8c10fdc000
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f8c10ddd000
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f8c10ddb000
+++ exited with 0 +++
glass bluff
#

you can massif too

ionic dust
#

so what is your g++ version

sinful silo
sinful silo
#

valgrind --tool=massif ./main
ms_print massif.out.xxxx

glass bluff
#

Yeah, just standard library init stuff

sinful silo
#

But this is platform dependent? I mean, do you also have a ~72kb heap allocation?

glass bluff
#

Pretty much every standard library is going to allocate a bit on the heap at the beginning for various things

ionic dust