Anonymous
by default
Anonymous
and this can cause bad memory leaks in robotics
Anonymous
which is why i prefer to work as close to the stack as possible
klimi
I'm getting notifications cuz warns and I thought that someone wants to talk T.T
Anonymous
you can just not use it 🤷🏻‍♀️
BinaryByter
and this can cause bad memory leaks in robotics
it cannot if you use a kernel that you didn'T write yourself
olli
C++ likes to do that
C++ does not use heap by default, The std::allocator does. Use custom ones if you see fit
Anonymous
which is one of the standard ones for RTOS
olli
to be honest, can you share "serious" code?
Anonymous
to be honest, can you share "serious" code?
do you mind if it is in like 6 hours or so?
Anonymous
if you are ok with that i am more then happy to give you some of the code i wrote
Anonymous
for one of my robotics projects
Anonymous
it will be minimalized because it is being sold currently to different universities
BinaryByter
olli
I still don't get why the heap causes memory leaks
Using memory on the heap can be leaked... It does not leak automatically..
Anonymous
I still don't get why the heap causes memory leaks
stack also does but it is much less common for stack memory leaks
olli
"can be leaked". how?
(void)new int(1000); ?
Anonymous
"can be leaked". how?
allocate and forget to deallocate
Anonymous
that memory gets used up
BinaryByter
(void)new int(1000); ?
emmmmmmmmmmmmmmm
BinaryByter
I mean
Anonymous
BinaryByter
sure
BinaryByter
if you do that
BinaryByter
but you can leak in the ram as well if you do that
Anonymous
if you do that
you also can just allocate and forget you allocated
BinaryByter
(void)new int(1000); ?
why cast to void? why not just new int [10000];
BinaryByter
you also can just allocate and forget you allocated
which you don'T do in C++ because you have nice things like... destructors
olli
why cast to void? why not just new int [10000];
to demonstrate it hasn't been assigned to anything
BinaryByter
not if you use pointers
WHICH YOU TYPICALLY DON'T DO IN C++
Anonymous
smart pointers?
Anonymous
WHICH YOU TYPICALLY DON'T DO IN C++
you do you just use smart pointers to try to prevent that
olli
smart pointers?
Use them in C++ for resource ownership
Anonymous
but even then it still happens
Anonymous
but even then it still happens
using smart pointers?
Anonymous
also which type of code do you want me to show? more of a server side one or a computation one?
BinaryByter
you do you just use smart pointers to try to prevent that
no, you litterally don'T use pointers in C++
BinaryByter
you use references
BinaryByter
unless you REALLY need pointers, but that is rather rare
olli
**Use pointer if nullptr is valid, otherwise use references**
Anonymous
yep
then that's a terrible code cuz it's even better than GC
Anonymous
you use references
references are not enough
Anonymous
how do i allocate more memory?
Anonymous
what if i need a new int?
Anonymous
like add an int to an array?
Anonymous
PCL also almost ALWAYS uses pointers
Anonymous
std::vector
yes this in turn USES A POINTER
Anonymous
or just test the module/class
olli
but even then it still happens
how (apart from cyclic references?)
olli
yes this in turn USES A POINTER
sure, how does it leak?
BinaryByter
which handles memory cleanly
Anonymous
Anonymous
sure, how does it leak?
it can if it is a global variable
Anonymous
or a file scope variable
Anonymous
and you just forget to deallocate it after using
Anonymous
std::vector
and what happens if i want to make a KD tree?
olli
it can if it is a global variable
Static data members are initialized and destroyed exactly like non-local objects (3.6.2, 3.6.3).
BinaryByter
that handles memory
BinaryByter
C++ != C with classes
BinaryByter
this is a C++ group
Anonymous
so say i make a file
Anonymous
have std::vector in there
Anonymous
i use it 1 time
BinaryByter
not if it is file scope
well if you global scope your stuff, theres something wrong with you
Anonymous
well if you global scope your stuff, theres something wrong with you
there are some reasons you want to global scope things such as you want mutexs
Anonymous
in robotics
BinaryByter
there are some reasons you want to global scope things such as you want mutexs
btw: if they are global scoped, you don't have that problem with heaps
olli
not if it is file scope
it has still static lifetieme duration where the sentence above applies