paullouisageneau / libjuice

JUICE is a UDP Interactive Connectivity Establishment library
Mozilla Public License 2.0
410 stars 76 forks source link

Call the libjuice library, call the library in cpp, the memory occupies 4M, call the library in pure C, the memory occupies 2.5M,Why? #187

Open LiuAriel opened 1 year ago

LiuAriel commented 1 year ago

This memory savings in embedded devices is very important, why is the memory gap so large.

Write a cpp file, compile the library with gcc, and then use a C++ class to call libjuice, use When g++ compiles and runs, the memory is 4M. In the same situation, I just implement the C function interface call, and the g++ compile and run memory is only 2.5M. Of course, the C++ class is the simplest structure, and there is no other processing. It seems that as long as any interface of the libjuice library is called by the C++ class, Memory immediately 2M VmRSS int main() { juice_set_log_level(JUICE_LOG_LEVEL_WARN); test_connectivity(); connectivity* conn = new connectivity(); conn->sendas(); while(true){ sleep(2); } return 0; } The above codes are saved in .cpp and .c respectively, compiled and run, and it is very clear to view vmRSS.

paullouisageneau commented 1 year ago

Isn't this issue a duplicate of https://github.com/paullouisageneau/libjuice/issues/162#issuecomment-1206205992 ?

I don't think that this is related to libjuice. You should use a proper tool like valgrind --tool=massif to profile the heap usage, as you can't really study the memory behavior of a program by only looking at VmRSS.

LiuAriel commented 1 year ago

This problem is different from the previous issue. In fact, you can quickly load the libjuice library and run the above code, and it is very clear to check the memory changes separately. This is not a memory leak problem.

There is this question mainly because of the use of c libraries such as srtp and usrsctp, there will be no such problems