#Heap usage of empty main program
54 messages · Page 1 of 1 (latest)
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.
@sinful silo
how did you create the executable ./main
Right
g++ -o main main.cpp
valgrind needs debug symbols I think otherwise it won't be able to track down the program
try building with
g++ -O0 -g main.cpp -o main
already done
what do you mean done, you did not tell g++ to add the debug symbols
I mean that even by doing it, the amount of bytes allocated is the same
to reveal where the leak is coming from rerun it with -s
valgrind -s ./main
wait a minute
Why there should be a leak in that program?
Yeah but you sayed this, you are confusing me :"D
I didn't see the picture then
now I see there are no leaks
So back to the question, do you know from where all those bytes come from?
let me try building this program mannually
yep
hmmmm I dont get any bytes allocated
show me your g++ --version and valgrind --version
You can find them in the screenshot
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.
That's probably allocation from the standard library
unless you're doing anything else
Can I recommend address sanitizer over valgrind
Even if I am not including any library at all?
72 KB of heap memory out of thin air? what for? I don't see this allocation
Indeed, I appreciate all kind of suggestion (:
Standard library io buffers my dude
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
But why he gets not byte allocated? How is that possible?
manually investigate where the system call mmap is called in your program
with strace
ok mine is way way bigger
so yes, the standard library is allocating memory
somewhere
kinda cringe, not gonna lie
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 +++
you can massif too
so what is your g++ version
What is massif?
11.2.0, as reported in the screenshot
valgrind --tool=massif ./main
ms_print massif.out.xxxx
Yeah, just standard library init stuff
But this is platform dependent? I mean, do you also have a ~72kb heap allocation?
Pretty much every standard library is going to allocate a bit on the heap at the beginning for various things
I do not hit this, so yeah, platform dependant probably