is there is a way to find out the total memory being consumed by my c++ program. is there is any tool or library by which i can find memory being consumed by my program.
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3831 |
3 | Radewoosh | 3646 |
4 | jqdai0815 | 3620 |
4 | Benq | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | gamegame | 3386 |
10 | ksun48 | 3373 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 164 |
1 | maomao90 | 164 |
3 | Um_nik | 163 |
4 | atcoder_official | 160 |
5 | -is-this-fft- | 158 |
6 | awoo | 157 |
7 | adamant | 156 |
8 | TheScrasse | 154 |
8 | nor | 154 |
10 | Dominater069 | 153 |
is there is a way to find out the total memory being consumed by my c++ program. is there is any tool or library by which i can find memory being consumed by my program.
Название |
---|
If you're using static arrays etc., you can use Custom Invocation to find out how much memory your code takes on Codeforces' servers.
i need to calculate memory on my computer, is there any other way? as i need to experimental comparison of space complexity of two algorithms for my project
(sizeof(array_0) + sizeof(array_1) + sizeof(array_2) + ... + sizeof(array_k)) / 1048576.0 gives you the size in megabytes
can you please explain what's this value "1048576.0" !! thanks
The
sizeof(a)
function returns the size of arraya
in bytes, so you need to divide the result by2^20 = 1048576
to convert it into megabytes.1 kb=1024 bytes 1 mb=1024 kb 1 mb=1024*1024=1048576
If you are on Linux, you can use POSIX getrusage
Read the man page to find out how it works.
These are the 2 elements of the struct you should be looking for.
If you don't need those informations in the program you can use the terminal program (if you use Linux)
/usr/bin/time
with the-v
flag.When I run this command terminal shows -v command not found
real 0m0.085s user 0m0.076s sys 0m0.004s
am i missing something?
Apparently you are using the Bash shell where
time
is a reserved word (seeman bash
— SHELL GRAMMAR — Pipelines). You have to spell it out asenv time -v ./a.out <input1 >output1
. Or perhaps addalias time='env time'
to your.bashrc
.The intended way to run a program when it is shadowed by a shell built-in is
Is there anything related with windows command ? Jakube
You mean you want to do the same thing on Windows?
From what I know, with the Windows Subsystem for Linux you have a (almost) full Linux environment and can just execute the same thing.
Alternatively you can also install any of other terminal emulators that are available, like cmder or Terminus. With those you can run the same command.
There's probably also some way of getting this to work on the Windows Command Prompt, or the Windows Powershell (later one is a lot more likely than the first), but the command will be completely different, and as I don't use Windows (neither for personal things or at my company), I have no idea.
if u only use arrays, or can figure out the maximum size of the data structure that you are using (vector,map,ect), you can just do math
assuming you declare int a[1000000], it means you declare 1000000 integers, 1 integer = 4 byte so 1000000 integers = 1000000 x 4 = 4000000 bytes = ~4 MB (1 B = ~1000000 MB)
same thing for vectors and others, but vectors are dynamic memory, so you can do it by calculating the worst case ammount of data in the structure